Jump to content

How to display message before redirect to other page


Recommended Posts



I'm trying to display a message first before redirect to other page, but my code just directly redirect the page without display the message.please help me.

if($num_rows == 0)
echo '<script type="text/javascript">alert("Please Enter Correct Details!");</script>'; 
header ('Location :login.php');
Link to comment
Share on other sites

The Location header tells the browser to ignore the response body and immediately jump to the specified page. So, no, it doesn't work like that.


You either need a meta element or a JavaScript-based redirect (which will obviously not work if JavaScript is turned off).


However, the whole idea is very bad as explained by the W3C in the link. Automatic redirects are generally confusing and can come at an inconvient time. What if the user was just about to do something on the page? This is 90s technology, we don't do that anymore. Either leave out the message stuff and just do an immediate redirect or implement a proper Ajax UI which handles this in a user-friendly way (this won't be easy).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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