akitchin Posted July 30, 2006 Share Posted July 30, 2006 a CRON job is next to useless for this task. as far as i know, there is no way to detect what sessions are currently active on the server, and as such, a CRON job serves no purpose. you need to run something on each page, so you'll want to include the file. a CRON is run by the server, not by a user, so it doesn't have access to the user's session information.are you currently storing the user's information when they log in? do you have a login system yet? if not, then this is all a pretty pointless exercise. Quote Link to comment https://forums.phpfreaks.com/topic/15715-auto-logout/page/2/#findComment-66074 Share on other sites More sharing options...
SieRobin Posted July 30, 2006 Author Share Posted July 30, 2006 alrighty, well i included the file on each page, still didn't work, and of course i took your script and dubbed it into my own settings.. dunno what's up with it i guess. Quote Link to comment https://forums.phpfreaks.com/topic/15715-auto-logout/page/2/#findComment-66105 Share on other sites More sharing options...
akitchin Posted July 30, 2006 Share Posted July 30, 2006 are you running log_action(), or are you just including the function definition file? Quote Link to comment https://forums.phpfreaks.com/topic/15715-auto-logout/page/2/#findComment-66117 Share on other sites More sharing options...
SieRobin Posted July 30, 2006 Author Share Posted July 30, 2006 i'm including a file with the log_action() in it called checkonline.php. Quote Link to comment https://forums.phpfreaks.com/topic/15715-auto-logout/page/2/#findComment-66142 Share on other sites More sharing options...
akitchin Posted July 31, 2006 Share Posted July 31, 2006 you have to actually RUN the function. put:[code]log_action();[/code]somewhere just below the function's definition. Quote Link to comment https://forums.phpfreaks.com/topic/15715-auto-logout/page/2/#findComment-66182 Share on other sites More sharing options...
SieRobin Posted July 31, 2006 Author Share Posted July 31, 2006 So I can include the file checkonline.php, but below the include i put, "log_action();"? Quote Link to comment https://forums.phpfreaks.com/topic/15715-auto-logout/page/2/#findComment-66220 Share on other sites More sharing options...
SieRobin Posted July 31, 2006 Author Share Posted July 31, 2006 Sorry, this is way confusing to me lol. Quote Link to comment https://forums.phpfreaks.com/topic/15715-auto-logout/page/2/#findComment-66238 Share on other sites More sharing options...
scottybwoy Posted July 31, 2006 Share Posted July 31, 2006 You can use a seperate file for hadling sessions, for portability. I have one se up that thats creates a session for each user. The session will then last as long as you set it up for in php.ini. Here one I borrowed from http://www.evoknow.com/downloads.phpNeed to connect to the database first.[code]$SESS_LIFE = get_cfg_var("session.gc_maxlifetime"); function sess_open($save_path, $session_name) { return true; } function sess_close() { return true; } function sess_read($key) { global $dbi, $DEBUG, $SESS_LIFE; $statement = "SELECT value FROM sessions WHERE " . "sesskey = $key AND expiry > " . time(); $result = $dbi->query($statement); if ($DEBUG) echo "sess_read: $statement <br>result: $result<br>"; $row = $result->fetchRow(); if ($row) { return $row->value; } return false; } function sess_write($key, $val) { global $dbi, $SESS_LIFE; $expiry = time() + $SESS_LIFE; $value = addslashes($val); $statement = "INSERT INTO sessions VALUES ('$key', $expiry, '$value')"; $result = $dbi->query($statement); if ($DEBUG) echo "sess_write: $statement <br>result: $result<br>"; if (! $result) { $statement = "UPDATE sessions SET expiry = $expiry, value = '$value' " . "WHERE sesskey = '$key' AND expiry > " . time(); $result = $dbi->query($statement); } return $result; } function sess_destroy($key) { global $dbi; $statement = "DELETE FROM sessions WHERE sesskey = '$key'"; $result = $dbi->query($statement); if ($DEBUG) echo "sess_destroy: $statement <br>result: $result<br>"; return $result; } function sess_gc($maxlifetime) { global $dbi; $statement = "DELETE FROM sessions WHERE expiry < " . time(); $qid = $dbi->query($statement); if ($DEBUG) echo "sess_gc: $statement <br>result: $result<br>"; return 1; } session_set_save_handler( "sess_open", "sess_close", "sess_read", "sess_write", "sess_destroy", "sess_gc");[/code]You need to make some other files first to talk to it.But shud give you all you need. Quote Link to comment https://forums.phpfreaks.com/topic/15715-auto-logout/page/2/#findComment-66412 Share on other sites More sharing options...
SieRobin Posted July 31, 2006 Author Share Posted July 31, 2006 [quote author=scottybwoy link=topic=101955.msg406530#msg406530 date=1154360871]You can use a seperate file for hadling sessions, for portability. I have one se up that thats creates a session for each user. The session will then last as long as you set it up for in php.ini. Here one I borrowed from http://www.evoknow.com/downloads.phpNeed to connect to the database first.[code]$SESS_LIFE = get_cfg_var("session.gc_maxlifetime"); function sess_open($save_path, $session_name) { return true; } function sess_close() { return true; } function sess_read($key) { global $dbi, $DEBUG, $SESS_LIFE; $statement = "SELECT value FROM sessions WHERE " . "sesskey = $key AND expiry > " . time(); $result = $dbi->query($statement); if ($DEBUG) echo "sess_read: $statement <br>result: $result<br>"; $row = $result->fetchRow(); if ($row) { return $row->value; } return false; } function sess_write($key, $val) { global $dbi, $SESS_LIFE; $expiry = time() + $SESS_LIFE; $value = addslashes($val); $statement = "INSERT INTO sessions VALUES ('$key', $expiry, '$value')"; $result = $dbi->query($statement); if ($DEBUG) echo "sess_write: $statement <br>result: $result<br>"; if (! $result) { $statement = "UPDATE sessions SET expiry = $expiry, value = '$value' " . "WHERE sesskey = '$key' AND expiry > " . time(); $result = $dbi->query($statement); } return $result; } function sess_destroy($key) { global $dbi; $statement = "DELETE FROM sessions WHERE sesskey = '$key'"; $result = $dbi->query($statement); if ($DEBUG) echo "sess_destroy: $statement <br>result: $result<br>"; return $result; } function sess_gc($maxlifetime) { global $dbi; $statement = "DELETE FROM sessions WHERE expiry < " . time(); $qid = $dbi->query($statement); if ($DEBUG) echo "sess_gc: $statement <br>result: $result<br>"; return 1; } session_set_save_handler( "sess_open", "sess_close", "sess_read", "sess_write", "sess_destroy", "sess_gc");[/code]You need to make some other files first to talk to it.But shud give you all you need.[/quote]Looks like a giant blur to me, lol. Quote Link to comment https://forums.phpfreaks.com/topic/15715-auto-logout/page/2/#findComment-66721 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.