kishan Posted September 30, 2008 Share Posted September 30, 2008 HI iam having a limit of 10 mins for the sessions in my app using.. if (!$_SESSION) { session_set_cookie_params(600); session_start(); } I want to echo a message when the session was timed out how can i know this ? i want ot differentiate the user was visited for the first time and the session was timed out..? Please help Thanks in advance Quote Link to comment Share on other sites More sharing options...
waynewex Posted September 30, 2008 Share Posted September 30, 2008 You could just simply redirect them to the login page with a get value such as: header('Location: login.php?timeout=Y'); Then on the timeout page you could show a message letting them know what happened. if(isset($_GET['timeout']) && $_GET['timeout'] == "Y"){ echo 'Your session timed out'; } Quote Link to comment Share on other sites More sharing options...
kishan Posted September 30, 2008 Author Share Posted September 30, 2008 Hi thanks for reply . yes but how can i know initially that my session was timed out . Quote Link to comment Share on other sites More sharing options...
waynewex Posted September 30, 2008 Share Posted September 30, 2008 When you start the session you could do something simple like: $_SESSION['logintime'] = mktime(); That will record a timestamp in seconds. Then on another page, simply compare the current time with the older time recorded in the session variable. $now = mktime(); if($now - $_SESSION['logintime'] > 600 ){ header('Location: login.php?timeout=Y'); } IF 60 seconds have passed, redirect. Probably not the best way to do it but it has done the job for me. Quote Link to comment Share on other sites More sharing options...
kishan Posted September 30, 2008 Author Share Posted September 30, 2008 But the way iam doing is correct? if (!$_SESSION) { session_set_cookie_params(600); session_start(); } because if i was not logged in this block will execute every time Quote Link to comment Share on other sites More sharing options...
revraz Posted September 30, 2008 Share Posted September 30, 2008 $_SESSION won't exist if you don't have session_start() before it. Quote Link to comment 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.