Summary of several issues that should be paid attention to when using PHPHeader for page jump. 1. there must be no 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 is executed. There cannot be spaces between 1, location, and: in asp. Otherwise, an error will occur.
2. there cannot be any output before using the header.
3. the PHP code after the header is executed.
The following is a comparison with response. redirect in asp:
Example 1:
Response. redirect ".../test. asp"
Header ("location: ../test. php ");
Differences:
The redirect function of asp can work after the header file is sent to the customer.
For example
<% Response. redirect ".../test. asp" %>
The following code in php reports an error:
Header ("location: ../test. php ");
?>
You can only do this:
Header ("location: ../test. php ");
?>
...
That is, the header function cannot send any data to the customer.
Example 2:
Asp
<%
Response. redirect ".../a. asp"
Response. redirect ".../B. asp"
%>
The result is to redirect the. asp file.
What about php?
Header ("location: ../a. php ");
Header ("location: ../B. php ");
?>
We found that it redirects B. php.
It turns out that after redirect is executed in asp, subsequent code will not be executed.
Php continues to execute the following code after executing the header.
In this regard, the header redirection in php is not as good as the redirection in asp. sometimes, after we want to redirect, we cannot execute the following code:
Generally, we use
If (...)
Header ("...");
Else
{
...
}
However, we can simply use the following method:
If (...)
{Header ("..."); exit ();}
Also note that if Unicode (UTF-8) encoding also causes problems, 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.jb51.net /')! =-1) location. href = '/index/index.htm ';
If (url. indexOf ('http: // www.kanshule.com /')! =-1) location. href = '/index1/index.htm ';
If (url. indexOf ('http: // www.shouji17.com /')! =-1) location. href = '/cn/index. asp ';
If (url. indexOf ('http: // www.baidu.com /')! =-1) location. href = '/cn/index. asp ';
Script
Bytes. 2. there cannot be any output before using the header. 3. the PHP code after the header is executed. Below is the redirection with asp...