Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: lost in PHP session

  1. #1
    Join Date
    Apr 2008
    Posts
    58
    Thanks
    22
    Thanked 0 Times in 0 Posts

    Default lost in PHP session

    hello i have a little trouble with php session ...
    i have read some php tutorials , but nothing is clear for me ...

    - i've created a web page with dynamic content.
    - i'm not using cookies
    - A php session is created with session_star() in each new page inserted.

    the problem , when the user login in all is fine , but when a page refresh is performed (using code or pressing F5), user is disconnected and so lost session and have to login again.

    the question is do i need to use cookies to keep the session alive after refresh ?? is there a way to keep the session (without cookies) until the browser is closed ?

  2. #2
    Join Date
    Apr 2008
    Posts
    58
    Thanks
    22
    Thanked 0 Times in 0 Posts

    Default

    i thought it would be a common problem, but i see nothing on google , and no reply here ...

  3. #3
    Join Date
    Apr 2008
    Posts
    58
    Thanks
    22
    Thanked 0 Times in 0 Posts

    Default

    If no one have ever experienced this problem , can you just show up how you do create a session (which stay alive after refreshing) ??

  4. #4
    Join Date
    Dec 2007
    Posts
    5
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    How long is your session timeout? You can check using the following bit of code mate.

    Code:
    // Get the current Session Timeout Value
    $currentTimeoutInSecs = ini_get(’session.gc_maxlifetime’);

  5. The Following User Says Thank You to rodneykm For This Useful Post:

    sfchun (11-20-2008)

  6. #5
    Join Date
    Apr 2008
    Posts
    58
    Thanks
    22
    Thanked 0 Times in 0 Posts

    Default

    timeout : 1440
    i think it's default settings

    but i don't think it comes from this , cause if i log on and perform a refresh just after, i get disconnected ... -_-;

  7. #6
    Join Date
    Oct 2008
    Location
    Columbia Md
    Posts
    27
    Thanks
    1
    Thanked 8 Times in 8 Posts

    Default

    Good Day,

    Will you post the code that is giving you trouble. It would help us try to help you.

  8. The Following User Says Thank You to olveyphotodesign For This Useful Post:

    sfchun (11-21-2008)

  9. #7
    Join Date
    Apr 2008
    Posts
    58
    Thanks
    22
    Thanked 0 Times in 0 Posts

    Default

    realy there is nothing much ...
    nothing more basic than this :

    PHP Code:
    <?php
            session_start
    ();
            
    $_SESSION['CurrentUser']=$User
            $_SESSION
    ['CurrentUPassword']=$uPasswd
            
    ...
            
    session_write_close();
    ?>
    then when i click on disconnect the code is this one :
    PHP Code:
    <?php
            session_start
    ();
            
    session_unset();
            
    session_destroy();
            echo 
    '<br />Byebye';
    ?>

  10. #8
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Default

    Hi.

    As you said, when you want to use SESSION variables put

    session_start();

    at the top of your page.

    It looks like you know how to assign SESSION variables too.

    Your session variables will remain until you "logout" by destroying "session_destory();" your session.

    Where are your variables $User and $uPasswd coming from?

    The code you posted is not all on the same page is it?

    I have never used session_write_close() before. I'll have to look it up.

    You do not need to set cookies to make session variables work.

    Sessions will remain in place after a refresh.

    Post all of the code you are using and we'll be able to figure it out. Sessions are pretty straight forward once you get the hang of it, so I think you must be making a simple mistake somewhere.

    Good Luck,

    Jason

  11. The Following User Says Thank You to JasonDFR For This Useful Post:

    sfchun (11-22-2008)

  12. #9
    Join Date
    Oct 2008
    Location
    Columbia Md
    Posts
    27
    Thanks
    1
    Thanked 8 Times in 8 Posts

    Default

    Good Evening,

    I think your problem lies in the session_write_close. Php.net states that this closes the current session. Therefore when you reload the page, the session has already been closed. Try commenting that function out and see if that fixes your problem.

    Good Luck,
    Ben

  13. The Following User Says Thank You to olveyphotodesign For This Useful Post:

    sfchun (11-22-2008)

  14. #10
    Join Date
    Apr 2008
    Posts
    58
    Thanks
    22
    Thanked 0 Times in 0 Posts

    Default

    Your session variables will remain until you "logout" by destroying "session_destory();" your session.

    Where are your variables $User and $uPasswd coming from?
    Variables comes from a form posted.
    I have no problem with them as i use them for all the time that the session is still alive.

    I think your problem lies in the session_write_close
    I've also though about this, but i can comment the line and nothing change.

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
  •