...

View Full Version : Keep sessions "alive"



Zoic
01-18-2010, 01:43 AM
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

JAY6390
01-18-2010, 02:36 AM
lol how ironic :)
If you run a script before the session runs out with just

<?php
session_start();
then it should keep the session alive. I'm a little confused as to why it does otherwise

Zoic
01-18-2010, 02:44 AM
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

JAY6390
01-18-2010, 03:00 AM
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

Zoic
01-18-2010, 07:13 AM
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. :rolleyes:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum