Jump to content

Closing a session


elmas156

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.