PHP pops up a prompt box and jumps to the new page to redirect to the new page

  • 2020-12-21 17:59:59
  • OfStack

In the past two days, I wrote one demo, which needed to use prompt and jump. The main page had low requirements, so I thought it was unnecessary to use AJAX, JS, etc. Therefore, I studied how to use prompt and jump in PHP.

It started with the following:
 
echo "<script> alert('sucess');parent.location.href='/user/index'; </script>"; 

alert is the prompt message, href is the page after the prompt jump.

Then I remembered that there was a method for redirect() redirection in the TP framework, so I took a look.

But TP doesn't come with a pop-up window, so it changed it:
 
echo "<script> alert('no loginid'); </script>"; 
echo "<meta http-equiv='Refresh' content='0;URL=$url'>"; 

$url is the page to jump to, and it also controls the jump time. The 0 after content means to jump after 0 seconds.

Here, MOE gives two more ways to jump directly:
 
header("Location:".PSYS_BASE_URL."user/index"); 

and
 
header("refresh:{$time};url={$url}"); 

These two ways no hint, direct jump. Recommend one of the following.

Finally, there is a problem with the jump code following an return, because the following statement is also executed

Related articles: