SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 27
  1. #1
    SitePoint Wizard
    Join Date
    Apr 2004
    Location
    dublin
    Posts
    2,036
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Session Problem!!

    Hi all,

    I have logged in on one page but when I continue onto the next page it says I am not logged in. Why is this?

    I put the session code(below) just after the DOCTYPE.
    PHP Code:
    <?php
    session_start
    (); 
    ?>
    Here is my checking code:
    PHP Code:
    // check session variable
      
    if (isset($HTTP_SESSION_VARS['valid_user']))
      {
       echo 
    '<h1>Logged in</h1><br />';
      }
      else
      { 
       echo 
    '<h1>You are not logged in!</h1>';
       exit;
      } 
    thanks.

    Kevin.

  2. #2
    SitePoint Evangelist Scheisskopf's Avatar
    Join Date
    Nov 2004
    Location
    Southampton, UK
    Posts
    537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it could be any number of things.

    I recomend checking what your session variables you have below session_start(), i.e.

    PHP Code:
    echo '<pre>';
    print_r($HTTP_SESSION_VARS);
    echo 
    '</pre>'

  3. #3
    SitePoint Enthusiast Bobbi's Avatar
    Join Date
    Mar 2005
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    After the doctype? AFAIK, you always need to call session_start() before you send ANYTHING to the browser ...

    Bobbi

  4. #4
    SitePoint Wizard
    Join Date
    Apr 2004
    Location
    dublin
    Posts
    2,036
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That just displays:

    Array{
    }

    any ideas? it worked fine on another server so maybe the config file??

  5. #5
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    what that basically means is the session isn't being registered in the first place. What code are you using to register the sessions?

    Spike
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  6. #6
    SitePoint Wizard
    Join Date
    Apr 2004
    Location
    dublin
    Posts
    2,036
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This code: it registers in this page but not the next. It worked fine on a previous server so maybe the config file??

    PHP Code:
    if (mysql_num_rows($result)>0)
      {
       
    // if they are in the database register the user id
       
    $HTTP_SESSION_VARS['valid_user'] = $username;
      }
      else {
       echo 
    '<h1>Unable to log in<br /><br />';
       echo 
    '<a href="#" onClick="history.go(-1)">Go Back</a></h1>';
       }
      
      
    // Check if registered session variable
      
    if (isset($HTTP_SESSION_VARS['valid_user']))
      {
       echo 
    '<h1>You are logged in as: '.$HTTP_SESSION_VARS['valid_user'].'<br /><br />';
       echo 
    '<a href="view.php">View Quiz Results</a><br /><br />';
       echo 
    '<a href="logout.php">Logout</a></h1><br />';
      }
      else
      {
       if (isset (
    $username))
       {
        
    // if they tried and failed to log in
        
    echo '<h1>Could not log you in</h1>';
       }
      } 

  7. #7
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    I may be wrong but I think that $HTTP_SESSION_VARS[] is deprecated. Try using $_SESSION['valid_user'] = $username

    It depends on the version of php your host is running.

    Cheers
    SpikeZ
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  8. #8
    SitePoint Wizard
    Join Date
    Apr 2004
    Location
    dublin
    Posts
    2,036
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Server is running PHP4.3 so shouldn't make a difference.

    Any ideas? Its pretty frustrating.

  9. #9
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Kev, note from the manual....


    Variables which are currently registered to a script's session. Analogous to the old $HTTP_SESSION_VARS array (which is still available, but deprecated). See the Session handling functions section for more information.

    So if the server is running a new version, it might not fully support the old way.

    Just a thought!

    S
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  10. #10
    SitePoint Enthusiast Bobbi's Avatar
    Join Date
    Mar 2005
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe you disabled cookies from your new servers IP or smth?

    Bobbi

  11. #11
    SitePoint Wizard
    Join Date
    Apr 2004
    Location
    dublin
    Posts
    2,036
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Changing $_HTTP_SESSION_VARS didnt work. How come I can log in on one page but then on the following page it says I am not logged in??

  12. #12
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Kev, just put on a new page the following code..
    PHP Code:
    <?
    session_start
    ();
    echo 
    '<pre>';
    print_r($_SESSION);
    echo 
    '</pre>';
    ?>
    That's it! Nothing else!!
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  13. #13
    SitePoint Wizard
    Join Date
    Apr 2004
    Location
    dublin
    Posts
    2,036
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Get same result as before: empty array -

    Array()

  14. #14
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Then its the registration process thats gone skewball.
    Add the
    echo '<pre>';
    print_r($_SESSION);
    echo '</pre>';

    part to the bottom of the page where the sessions are registered to check they are registered....
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  15. #15
    SitePoint Evangelist Scheisskopf's Avatar
    Join Date
    Nov 2004
    Location
    Southampton, UK
    Posts
    537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try changing
    PHP Code:
    <?
    session_start
    ();
    echo 
    '<pre>';
    print_r($_SESSION);
    echo 
    '</pre>';
    ?>
    tp
    PHP Code:
    <?
    session_start
    ();
    echo 
    '<pre>';
    print_r($_HTTP_SESSION_VARS);
    echo 
    '</pre>';
    ?>

  16. #16
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Scheisskopf, tried that further up the thread!!
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  17. #17
    SitePoint Wizard
    Join Date
    Apr 2004
    Location
    dublin
    Posts
    2,036
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by spikeZ
    Then its the registration process thats gone skewball.
    Add the
    echo '<pre>';
    print_r($_SESSION);
    echo '</pre>';

    part to the bottom of the page where the sessions are registered to check they are registered....
    did that SpikeZ. Got this result on the page that logs me in but in the following page it displayed the empty array:

    Array( [valid_user] => administrator)So what Should I do?

  18. #18
    SitePoint Wizard
    Join Date
    Apr 2004
    Location
    dublin
    Posts
    2,036
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyone??

  19. #19
    SitePoint Evangelist Scheisskopf's Avatar
    Join Date
    Nov 2004
    Location
    Southampton, UK
    Posts
    537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Theres a difference between using something like
    PHP Code:
    $_SESSION('var'); 
    and
    PHP Code:
    $_SESSION(var); 
    I think the former may declare a constant.Yours seems to be the latter, so when checking remove the single quotes.

  20. #20
    SitePoint Wizard
    Join Date
    Apr 2004
    Location
    dublin
    Posts
    2,036
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I still get an empty array!

  21. #21
    SitePoint Enthusiast Bobbi's Avatar
    Join Date
    Mar 2005
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Looks like a cookie issue to me ... but as I feel kinda ignored in this thread for now, excuse for disturbing you

    Bobbi

  22. #22
    SitePoint Wizard
    Join Date
    Apr 2004
    Location
    dublin
    Posts
    2,036
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry Bobbi. didnt mean to ignore you.

    How can I solve this issue??

    Thanks.

  23. #23
    SitePoint Evangelist Scheisskopf's Avatar
    Join Date
    Nov 2004
    Location
    Southampton, UK
    Posts
    537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you tried
    PHP Code:
    // check session variable
      
    if (isset($HTTP_SESSION_VARS['valid_user']))
      {
       echo 
    '<h1>Logged in</h1><br />';
      }
      else
      {
       echo 
    '<h1>You are not logged in!</h1>';
       exit;
      } 

  24. #24
    SitePoint Wizard
    Join Date
    Apr 2004
    Location
    dublin
    Posts
    2,036
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yup. Did that

  25. #25
    SitePoint Evangelist Scheisskopf's Avatar
    Join Date
    Nov 2004
    Location
    Southampton, UK
    Posts
    537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry, i mean
    PHP Code:
    // check session variable
      
    if (isset($HTTP_SESSION_VARS[valid_user]))
      {
       echo 
    '<h1>Logged in</h1><br />';
      }
      else
      {
       echo 
    '<h1>You are not logged in!</h1>';
       exit;
      } 


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
  •