funbinod Posted January 16, 2015 Share Posted January 16, 2015 (edited) 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 January 16, 2015 by funbinod Link to comment Share on other sites More sharing options...
Ingolme Posted January 16, 2015 Share Posted January 16, 2015 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. 1 Link to comment Share on other sites More sharing options...
bonvisao Posted February 2, 2015 Share Posted February 2, 2015 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now