Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jan 2010
    Location
    UT
    Posts
    35
    Thanks
    1
    Thanked 3 Times in 3 Posts

    Keep sessions "alive"

    What I'm trying to accomplish is a combination of using PHP and AJAX to keep sessions "alive" so to speak, so that if the person comes back like an hour and a half later, they won't be logged out of the site and have to type in their credentials again.

    Sorry, but I can't really provide a link/demo to this.

    On each of my pages, a timeout clock starts that counts to 30 mins. Each time you view a page, the timer obviously starts over. If it reaches 30 mins, a dialog box shows that says "Your session has expired." and provides a link to log back in. Not only that, but it then beings to run a "keepAlive()" function that uses AJAX to run a PHP file every so often in an attempt to keep the session from expiring on the server. The PHP file that runs starts the session and sets a session variable to a static value. However, it doesn't seem like this works properly and doesn't keep the session "alive" on the server, so it expires after an hour. When the user comes back after it expires, the login link no longer works.

    I've been testing different approaches over the past couple days but haven't had too much success.

    Thoughts?


    // edit: lol funny... while I was typing up this post, I hit submit and it ended up making me login again

  • #2
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    lol how ironic
    If you run a script before the session runs out with just
    PHP Code:
    <?php
    session_start
    ();
    then it should keep the session alive. I'm a little confused as to why it does otherwise
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #3
    New Coder
    Join Date
    Jan 2010
    Location
    UT
    Posts
    35
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Yeah, I am confused too, which is why I haven't figured it out yet. I guess I'll just have to keep tinkering around with it and figure out what the culprit might be. Testing takes forever... lol

  • #4
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    Are you sure the calls are going through to the server ok? Make the script return a value and get the ajax call to alert() the result when it sends just so you know it's worked
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #5
    New Coder
    Join Date
    Jan 2010
    Location
    UT
    Posts
    35
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Silly me... I was using setTimeout() instead of setInterval() in the javascript lol so it was only calling the PHP file once instead of over and over again.


  •  

    Posting Permissions

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