Objective
This article describes the use of a jump in PHP header("location:test.php")
to pay attention to the following points to help solve some novice frequently encountered problems
One, location and ":" No space between the number, or there will be errors.
Second, no output before using header.
Three, after the header of the PHP code will also be executed.
The following is a comparison of redirects with ASP response.redirect
:
Example 1:
Response.Redirect ". /test.asp
Header ("Location:.") /test.php ");
The difference between the two:
An ASP's redirect
function can work after sending a header file to a customer.
Such as
Check that the next code in PHP will report an error:
You can only do this:
?
Header ("Location:.") /test.php ");
? >
That is, the header function cannot send any data to the customer.
Example 2:
in ASP
The result is a redirected a.asp file.
What about PHP?
?
Header ("Location:.") /a.php ");
Header ("Location:.") /b.php ");
? >
We found it redirected to b.php.
The following code is not executed after the redirect is executed in ASP.
and PHP continues to execute the following code after executing the header.
In this respect the header redirection in PHP is not as redirected as in ASP. Sometimes after we redirect, we can't execute the following code:
In general, we use
if (...)
Header ("...");
else
{
...
}
But we can simply use the following methods:
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%>
<script>
var url = location.href;
if (Url.indexof (' http://www.devdao.com/')!=-1) location.href= '/index/index.htm ';
if (Url.indexof (' http://www.knowsky.com/')!=-1) location.href= '/index1/index.htm ';
if (Url.indexof (' http://www.google.com/')!=-1) location.href= '/cn/index.asp ';
if (Url.indexof (' http://www.baidu.com/')!=-1) location.href= '/cn/index.asp ';
</script>
Summarize
The above is the entire content of this article, I hope to be able to learn or work to bring certain help, if you have questions you can message exchange.