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 Link to comment https://forums.phpfreaks.com/topic/126424-session-expire/ Share on other sites More sharing options...
waynew 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'; } Link to comment https://forums.phpfreaks.com/topic/126424-session-expire/#findComment-653728 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 . Link to comment https://forums.phpfreaks.com/topic/126424-session-expire/#findComment-653734 Share on other sites More sharing options...
waynew 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. Link to comment https://forums.phpfreaks.com/topic/126424-session-expire/#findComment-653736 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 Link to comment https://forums.phpfreaks.com/topic/126424-session-expire/#findComment-653739 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. Link to comment https://forums.phpfreaks.com/topic/126424-session-expire/#findComment-653794 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.