elmas156 Posted October 14, 2008 Share Posted October 14, 2008 Hello everyone, hopefully this will be pretty simple... I need to know how to make a session close, either when the browser is closed or when a certain time, say 10 minutes, has passed with no activity. I was hosting my site on a free hosting server and it would do this automatically but now I've transferred my site and it will stay open until I manually clear the cache and cookies. Any input would be greatly appreciated. Link to comment https://forums.phpfreaks.com/topic/128316-closing-a-session/ Share on other sites More sharing options...
mukunthan Posted October 14, 2008 Share Posted October 14, 2008 ini_set("session.gc_maxlifetime", 60); Hope this works for u. Otherwise store the loggedin time in a session var, then write a check condition to check it with the current time. If time diff is >10mins kill the sesion by session_destroy(); Link to comment https://forums.phpfreaks.com/topic/128316-closing-a-session/#findComment-664722 Share on other sites More sharing options...
mukunthan Posted October 14, 2008 Share Posted October 14, 2008 in your case ini_set("session.gc_maxlifetime", 600);// 600 secs Link to comment https://forums.phpfreaks.com/topic/128316-closing-a-session/#findComment-664724 Share on other sites More sharing options...
elmas156 Posted October 15, 2008 Author Share Posted October 15, 2008 great! would I put this code on every page or would I put it only in the code to start the session?? Here is the code that I'm using to start my session: <?php $email = form($_POST['email']); $pword = md5($_POST['pword']); // Encrypts the password. $q = mysql_query("SELECT * FROM `users` WHERE email = '$email' AND pword = '$pword'") or die (mysql_error()); // mySQL query $r = mysql_num_rows($q); // Checks to see if anything is in the db. if ($r == 1) { // There is something in the db. The username/password match up. $_SESSION['logged'] = 1; // Sets the session. $_SESSION['email'] = $email; echo "<meta http-equiv=\"refresh\" CONTENT=\"0; URL=members.php\">"; // Goes to main page. exit(); // Stops the rest of the script. } ?> Link to comment https://forums.phpfreaks.com/topic/128316-closing-a-session/#findComment-666536 Share on other sites More sharing options...
elmas156 Posted October 16, 2008 Author Share Posted October 16, 2008 BUMP... just trying to get some quick help... Thanks everyone. Link to comment https://forums.phpfreaks.com/topic/128316-closing-a-session/#findComment-666760 Share on other sites More sharing options...
darkfreaks Posted October 16, 2008 Share Posted October 16, 2008 try using exit(0); or just plain exit; Link to comment https://forums.phpfreaks.com/topic/128316-closing-a-session/#findComment-666772 Share on other sites More sharing options...
elmas156 Posted October 16, 2008 Author Share Posted October 16, 2008 I want the session to stay open while the user is navigating through the pages but I don't want the session to stay open for hours afterward, which is what is happening now. I can't really close the session after exiting a certain page because they may need to come back to that page during the session... Am I making sense? Now I'm getting confused... Link to comment https://forums.phpfreaks.com/topic/128316-closing-a-session/#findComment-666779 Share on other sites More sharing options...
trq Posted October 16, 2008 Share Posted October 16, 2008 php sessions should die automatically (default is 20 mins I think). What does the following produce? <?php echo ini_get('session.gc_maxlifetime'); ?> Link to comment https://forums.phpfreaks.com/topic/128316-closing-a-session/#findComment-666794 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.