Results 1 to 9 of 9

Thread: Need some help with a PHP script for my user system.

  1. #1
    Join Date
    Apr 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Need some help with a PHP script for my user system.

    Hello,

    Ok i got this script that hides any content if your not logged in, as it checks if username is active *code below*:

    Code:
    if($_SESSION["s_username"]
    if the username is logged in it will display the content that is wrapped in between "?>" and "<?php } ?>". heres an example below:

    Code:
    <?php
    
    if($_SESSION["s_username"]){
    
    
    ?>
    
    <p><DIV class=content-page-register style="width: 342px; height: 2px">
    <font color="#808080">Welcome Back, <?php echo $_SESSION['s_username'] ?>!</font></DIV></p>
    
    <?php } ?>
    And that would display "if logged in" (Welcome Back, Username!).

    But what i am after is that while it hides the content i want it to display a message something like:

    "You must be registered or logged in, to use this feature" but i don't know what statement i would need to use to display that ? Any help would be very much appreciated .

    Thanks,
    Ben

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Try adding this to your script (the part in red):

    Code:
    <?php
    
    if($_SESSION["s_username"]){
    
    
    ?>
    
    <p><DIV class=content-page-register style="width: 342px; height: 2px">
    <font color="#808080">Welcome Back, <?php echo $_SESSION['s_username'] ?>!</font></DIV></p>
    
    <?php }
    
    else {
    ?>
    <p><DIV class=content-page-register style="width: 342px; height: 2px">
    <font color="#808080">You must be registered or logged in, to use this feature!</font></DIV></p>
    <?php
    }
    ?>
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Apr 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks thetestingsite,

    That worked great!

    And thanks for the help

    Ben

  4. #4
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    No problem, let us know if you need any more help.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  5. #5
    Join Date
    Apr 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Well this another thing, that i got a comment system for my news articles.
    But the problem lays on the date & time posted, it displays the date correctly but the time and timezone are posted incorrectly as it will display PDT timezone. And i don't know how it make it use GMT timezone.

    This is how it's echoed:

    Code:
    <input type="hidden" name="posted" value="<?php echo date("F j, Y, g:i a T"); ?>">
    Any ideas why it's using PDT timezone? and any ideas how to fix this?

    Any help would be appreciated!

    Ben

  6. #6
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Is your server hosted in the PDT timezone? If so, that is the reason why it is displaying like so. A fix would be to use gmdate, an example is like so:

    Code:
    echo gmdate("F j, Y, g:i a T", time());
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  7. #7
    Join Date
    Apr 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks,

    But the problem is that now its displaying the wrong time like an hour behind this is what i just got when i posted a comment:

    April 7, 2007, 5:18 pm GMT

    Which it should of been 6:18pm

    i know it would be something like GMT+1, something like that.

    Ben

  8. #8
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    It may be due to daylight savings time or something to that effect. Other than that, it should be fine.
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  9. #9
    Join Date
    Apr 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for your help

    It's probably due to that clocks went back, but i could be wrong but im happy with it. And it isn't a big issue to be honest so thanks anyways!

    Ben

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •