j.smith1981 Posted May 19, 2011 Share Posted May 19, 2011 I was wanting to make some kind of session timeout ability, just purely out of curiosity. I have tried going off my own theory, before looking at any tutorials, well have looked a bit but tried getting the jist and having a go myself the next day (anyways that being said), this code here: <?php ini_set('display_errors', 1); session_name("jeremysmith_test_session"); session_start(); $_SESSION['start_time'] = time(); if($_SESSION['start_time'] < $_SESSION['start_time'] + 500) { printf("Time out be out dated!"); } Just does not seem to want to work, is there any reason for this, that you could think of? I appreciate any replies, Jeremy. Quote Link to comment https://forums.phpfreaks.com/topic/236832-correct-way-of-doing-a-php-timeout/ Share on other sites More sharing options...
trq Posted May 19, 2011 Share Posted May 19, 2011 Look at it. On each request you set $_SESSION['start_time'] to the current time. Meaning, it will always equal less than the current time + 500. You need to set an end_time on the first request and check start_time against that on subsequent requests. Quote Link to comment https://forums.phpfreaks.com/topic/236832-correct-way-of-doing-a-php-timeout/#findComment-1217424 Share on other sites More sharing options...
j.smith1981 Posted May 19, 2011 Author Share Posted May 19, 2011 Oh ok then that is fine. Will work this one out and try it out maybe on a subsequent page, just to make it feel like a real system so to speak. I mean for a user defined time out, it is in seconds is not it? I mean if a user was to say not use a no time out, in a checkbox element, they could say want their login valid for 60minutes, but in the way their inputting it, would be multiplied by 60? Am I thinking about this correctly? Plus if I wanted to do purely MySQL authentication time outs, then I would set when the users session would become invalid right? Saying something like: <?php ['sessiontime'] <= time(); ?> Am I thinking alright about this? Thank you for your reply and I look forward to your next response, Jeremy. Quote Link to comment https://forums.phpfreaks.com/topic/236832-correct-way-of-doing-a-php-timeout/#findComment-1217431 Share on other sites More sharing options...
trq Posted May 19, 2011 Share Posted May 19, 2011 I have no idea what your talking about. Quote Link to comment https://forums.phpfreaks.com/topic/236832-correct-way-of-doing-a-php-timeout/#findComment-1217490 Share on other sites More sharing options...
j.smith1981 Posted May 19, 2011 Author Share Posted May 19, 2011 Sorry it does not matter got it working now: if(time() >= $_SESSION['timeout'] ) Obviously me just waffling, but got it working, using say time() + 60 * 60 (so I can theoretically set a text box, that a user can enter to say how long they want their session (if I allow this), for them to stay logged in or a checkbox to allow them to stay permenantly logged in. Thank you for all your help, just needed to go over some logic. Jeremy. Quote Link to comment https://forums.phpfreaks.com/topic/236832-correct-way-of-doing-a-php-timeout/#findComment-1217509 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.