Home  >  Article  >  Backend Development  >  Summary of several issues to pay attention to when using PHP Header for page jumps

Summary of several issues to pay attention to when using PHP Header for page jumps

高洛峰
高洛峰Original
2016-12-20 11:09:211191browse

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%>



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!

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