Jump to content

How to display message before redirect to other page


Tje

Recommended Posts

Hi,

 

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');
}

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

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.