Jump to content

alert before redirecting


funbinod

Recommended Posts

can I make an alert display before redirecting a page?

 

I tried this but it gave error "headers already sent............"

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

and the $_SESSION['timeout'] also did not work either...

Edited by funbinod
Link to comment
Share on other sites

You can't print anything before sending a header because in an HTTP request headers must always get sent before the content.

 

If you send a location header, the user's not going to see what you printed anyways because the browser would immediately jump to the next page.

 

To get around this you can make Javascript perform the redirect instead of sending a header.

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

You can't print anything before sending a header because in an HTTP request headers must always get sent before the content.

 

If you send a location header, the user's not going to see what you printed anyways because the browser would immediately jump to the next page.

 

To get around this you can make Javascript perform the redirect instead of sending a header.

Yes .

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...