phpcode Posted January 4, 2008 Share Posted January 4, 2008 I know how to create a session id but what I want to know how would I make a session invalid if the user with that ID is inactive for over 1 minute? Quote Link to comment https://forums.phpfreaks.com/topic/84386-solved-session-id-help/ Share on other sites More sharing options...
phpSensei Posted January 4, 2008 Share Posted January 4, 2008 use session_unset(); the username, and stuff. Quote Link to comment https://forums.phpfreaks.com/topic/84386-solved-session-id-help/#findComment-429824 Share on other sites More sharing options...
awpti Posted January 4, 2008 Share Posted January 4, 2008 Either use cookies or reset a session on every pageload checking for difference in unixtime. <?php if(!$_SESSION['last_active)) { $_SESSION['last_active'] = date("U"); } else { if( (date("U") - 60) > $_SESSION['last_active'] ) { $_SESSION['valid_user'] = 0; } } ?> Really generic. Try to use cookies. 60 seconds is also kinda short. Guess it depends on your goal. (I didn't test the above code, that's off the top of my head, check for logic/syntax). Quote Link to comment https://forums.phpfreaks.com/topic/84386-solved-session-id-help/#findComment-429828 Share on other sites More sharing options...
revraz Posted January 4, 2008 Share Posted January 4, 2008 Or just edit the php.ini and change the session timeout to 60 seconds. Quote Link to comment https://forums.phpfreaks.com/topic/84386-solved-session-id-help/#findComment-429829 Share on other sites More sharing options...
cooldude832 Posted January 4, 2008 Share Posted January 4, 2008 I know how to create a session id but what I want to know how would I make a session invalid if the user with that ID is inactive for over 1 minute? How do you know they are inactive fro 1 min? Quote Link to comment https://forums.phpfreaks.com/topic/84386-solved-session-id-help/#findComment-429830 Share on other sites More sharing options...
phpcode Posted January 4, 2008 Author Share Posted January 4, 2008 Either use cookies or reset a session on every pageload checking for difference in unixtime. <?php if(!$_SESSION['last_active)) { $_SESSION['last_active'] = date("U"); } else { if( (date("U") - 60) > $_SESSION['last_active'] ) { $_SESSION['valid_user'] = 0; } } ?> Really generic. Try to use cookies. 60 seconds is also kinda short. Guess it depends on your goal. (I didn't test the above code, that's off the top of my head, check for logic/syntax). Doesn't work. Quote Link to comment https://forums.phpfreaks.com/topic/84386-solved-session-id-help/#findComment-429962 Share on other sites More sharing options...
redarrow Posted January 4, 2008 Share Posted January 4, 2008 did you read up on session_start(); Quote Link to comment https://forums.phpfreaks.com/topic/84386-solved-session-id-help/#findComment-429966 Share on other sites More sharing options...
awpti Posted January 4, 2008 Share Posted January 4, 2008 Either use cookies or reset a session on every pageload checking for difference in unixtime. <?php if(!$_SESSION['last_active'])) { $_SESSION['last_active'] = date("U"); } else { if( (date("U") - 60) > $_SESSION['last_active'] ) { $_SESSION['valid_user'] = 0; } } ?> Really generic. Try to use cookies. 60 seconds is also kinda short. Guess it depends on your goal. (I didn't test the above code, that's off the top of my head, check for logic/syntax). Doesn't work. Yeah, there's a typo in it As said, it's not tested. YMMV. Play a little bit, you'll figure it out. Quote Link to comment https://forums.phpfreaks.com/topic/84386-solved-session-id-help/#findComment-429969 Share on other sites More sharing options...
phpcode Posted January 4, 2008 Author Share Posted January 4, 2008 I saw the typo this is what I did to it: <?php if(!$_SESSION['last_active']) { $_SESSION['last_active'] = date("U"); } else { if( (date("U") - 60) > $_SESSION['last_active'] ) { $_SESSION['valid_user'] = 0; } } echo $_COOKIE["PHPSESSID"]; ?> Quote Link to comment https://forums.phpfreaks.com/topic/84386-solved-session-id-help/#findComment-429971 Share on other sites More sharing options...
redarrow Posted January 4, 2008 Share Posted January 4, 2008 <?php session_start(); //<<< this was missing hay if(!$_SESSION['last_active']) { $_SESSION['last_active'] = date("U"); } else { if( (date("U") - 60) > $_SESSION['last_active'] ) { $_SESSION['valid_user'] = 0; } } echo $_COOKIE["PHPSESSID"]; ?> Quote Link to comment https://forums.phpfreaks.com/topic/84386-solved-session-id-help/#findComment-429973 Share on other sites More sharing options...
phpcode Posted January 4, 2008 Author Share Posted January 4, 2008 That doesn't create sessions. Quote Link to comment https://forums.phpfreaks.com/topic/84386-solved-session-id-help/#findComment-429981 Share on other sites More sharing options...
redarrow Posted January 4, 2008 Share Posted January 4, 2008 session_start() creates a session or resumes the current one based on the current session id that's being passed via a request, such as GET, POST, or a cookie. http://uk3.php.net/session_start does it <<<<<<<<< read <<<<<<<<<<< Quote Link to comment https://forums.phpfreaks.com/topic/84386-solved-session-id-help/#findComment-429989 Share on other sites More sharing options...
phpcode Posted January 4, 2008 Author Share Posted January 4, 2008 Thanks Quote Link to comment https://forums.phpfreaks.com/topic/84386-solved-session-id-help/#findComment-430767 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.