Jump to content

does not alert after logout


funbinod

Recommended Posts

hi guys!

 

this is somewhat related to my previous post about automatic session timeout.

 

I calculated timeout time from sessions table and forced the user logout if (s)he exceeded the timeout limit. it did exactly what I expected from the following code

$slaquery = mysqli_query($connect, "SELECT lastActive FROM session WHERE cid='$cid' AND uid='$uid'") or die ("Error: ".mysqli_error($connect));$slarow = mysqli_fetch_object($slaquery);$lastActive = $slarow->lastActive;$time = time();if ($time - $lastActive > 1200) {	echo"<script>alert('Timeout!');</script>";	mysqli_query($connect, "DELETE FROM session WHERE cid='$cid' AND uid='$uid'") or die("Error: ".mysqli_error($connect));	$user->logout();	die(header("location: login.php"));}

but it did not alert (or echo) the Timeout! as written on line 25. if I changed the code to create error session like this --

session_start();$_session['error'] = 'Timeout!';die(header('location: login.php');

using this, it prints other error sessions at login.php but doesn't print the 'Timeout!'.

 

what could be the mistake.....

Link to comment
Share on other sites

this is logout function

	public function logout() {		$this->isLoggedIn = false;		if (session_id() == '') {			session_start();		}		$_SESSION['isLoggedIn'] = false;		foreach ($_SESSION as $key => $value) {			$_SESSION['$key'] = "";			unset($_SESSION[$key]);		}		$_SESSION = array();		if (ini_get("session.use_cookies")) {			$cookieParameters = session_get_cookie_params();			setcookie(session_name(), '', time() - 1200, $cookieParameters['path'],$cookieParameters['domain'],$cookieParameters['secure'],$cookieParameters['httponly']);		}		session_destroy();	}
Link to comment
Share on other sites

You probably got an error message that didn't show up because you have error reporting disabled.

 

You can't print any content before sending a header. No echo statements or HTML. headers have to be the first thing sent to the client.

 

When you redirect to another page, there's no point at all in displaying any content because the user is leaving the current page. Put the alert message on the destination page instead.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...