1, location and ":" No space between, otherwise it will be wrong.
2, before using the header can not have any output.
3. The PHP code after the header will also be executed.
Here is a comparison with the redirect Response.Redirect in asp:
Example 1:
Response.Redirect ". /test.asp "
Header ("Location:.. /test.php ");
The difference between the two:
The redirect function of an ASP can work after sending a header file to the customer.
Such as
<%response.redirect ". /test.asp "%>
Check that the following code in PHP will report an error:
Header ("Location:.. /test.php ");
?>
This is the only way:
Header ("Location:.. /test.php ");
?>
...
That is, the header function cannot send any data to the customer before.
Example 2:
in ASP
<%
Response.Redirect ". /a.asp "
Response.Redirect ". /b.asp "
%>
The result is a redirected a.asp file.
What about PHP?
Header ("Location:.. /a.php ");
Header ("Location:.. /b.php ");
?>
We found it redirected b.php.
The subsequent code is no longer executed after executing redirect in ASP.
PHP continues to execute the following code after the header is executed.
In this regard, header redirection in PHP is not as good as redirection in ASP. Sometimes after we redirect, we cannot execute the following code:
Generally, we use
if (...)
Header ("...");
Else
{
...
}
But we can simply use the following method:
if (...)
{Header ("..."); exit ();}
Also note that if there is a problem with Unicode (UTF-8) encoding, you need to adjust the cache settings.
<[email=%@]% @LANGUAGE = "Vbscript[/email]" codepage= "936"%>
<%if request.servervariables ("server_name") = "S.jb51.net" Then
Response.Redirect "News/index.htm"
Else%>
<%end if%>
http://www.bkjia.com/PHPjc/319488.html www.bkjia.com true http://www.bkjia.com/PHPjc/319488.html techarticle 1, location and ":" No space between, otherwise it will be wrong. 2, before using the header can not have any output. 3. The PHP code after the header will also be executed. The following is the redirect with ASP ...