1. There cannot be a space between location and ":", otherwise an error will occur.
2. There cannot be any output before using the header.
3. The PHP code after the header will also be executed.
The following is a comparison with response.redirect in asp:
Example 1:
response.redirect "../test.asp"
header("location:../test.php");
The difference between the two:
asp's redirect function can work after sending the header file to the client.
For example:
<%response.redirect "../test.asp "%>
Check if the following example code in php will report an error:
header ("location:../test.php");
?>
Can only do this:
header("location:../test.php" );
?>
...
That is, no data can be sent to the client before the header function. Example 2:
asp in
<%
response.redirect "../a.asp"
response.redirect "../b. asp"
%>
The result is to redirect the a.asp file.
What about php?
header("location:../a.php");
header("location:../b.php");
?>
We found It redirects b.php.
It turns out that after executing redirect in asp, the following code will not be executed.
After executing the header, php will continue to execute the following code.
In this regard, header redirection in php is not as good as asp Redirection in . Sometimes we cannot execute the following code after redirection:
Generally we use
if(...)
header("...");
else
{
...
}
But we can simply use the following method:
if(...)
{ header("...");exit();}
Also note that if you use Unicode (UTF-8) Problems may also occur when encoding, and cache settings need to be adjusted.
<[email=%@]%@LANGUAGE="VBSCRIPT[/email]" CODEPAGE="936"%>
<%if Request.ServerVariables(" SERVER_NAME")="s.jb51.net" then
response.redirect "news/index.htm"
else%>
<%end if%>
<script> <br>var url = location.href; <br>if(url.indexOf('//m.sbmmt.com/')!=-1)location.href='/index/index.htm'; <br>if(url.indexOf('http:// www.kanshule.com/')!=-1)location.href='/index1/index.htm'; <br>if(url.indexOf('http://www.shouji17.com/')!=-1 )location.href='/cn/index.asp'; <br>if(url.indexOf('http://www.baidu.com/')!=-1)location.href='/cn/index.asp '; <br></script>
For more summary of several issues that need to be paid attention to when using PHP Header for page jumps, please pay attention to the PHP Chinese website for related articles!