Home  >  Article  >  Backend Development  >  PHP header method jump page problem

PHP header method jump page problem

coldplay.xixi
coldplay.xixiOriginal
2020-07-27 15:37:453629browse

php header method to jump to the page: 1. Jump immediately, the code is [header('Location:other.php')]; 2. Jump prompt, the code is [header('Refresh:3, Url=other.php');echo 'jump after 3s'].

PHP header method jump page problem

php header method jumps to the page:

header() is a php function, Send the specified command to the browser

html:

<meta http-equiv="Refresh" content="3;url=other.php"/>

Jump immediately:

header(&#39;Location:other.php&#39;);
//file_put_contents(&#39;bee.txt&#39;,&#39;execute&#39;);
die;

When executing the header, it does not end immediately, but the page will be executed; There cannot be any output in front of the header. If the output buffer is turned on, no error will be prompted.

php.ini->output_buffering = 4096|OFF

Prompt jump:

header(&#39;Refresh:3,Url=other.php&#39;);
echo &#39;3s 后跳转&#39;;
//由于只是普通页面展示,提示的样式容易定制
die;

Encapsulated jump function:

/*
 *跳转
 *@param $url 目标地址
 *@param $info 提示信息
 *@param $sec 等待时间
 *return void
*/
function jump($url,$info=null,$sec=3)
{
 if(is_null($info)){
  header("Location:$url");
 }else{
  // header("Refersh:$sec;URL=$url");
  echo"<meta http-equiv=\"refresh\" content=".$sec.";URL=".$url.">";
  echo $info;
 }
 die;
}

Related learning recommendations: PHP programming from entry to proficiency

The above is the detailed content of PHP header method jump page problem. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn