We are1, location and ":" No space between, otherwise it will be wrong.
2, before using the header can not have any output.
3, PHP code after using 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
- < html > < head > !-- head > < body >
- < % Response.Redirect ". /test.asp "% ;
- body > span class= "tag" >!-- html > strong>
Check is in PHP with the header in the next example code will be error:
- <html><head> head > < Body >
-
- Header ("Location:.. /test.php ");
- ?>
- body> html>
This is the only way:
-
- Header ("Location:.. /test.php ");
- ?>
- < HTML > < Head > head><body> ... body> html>
That is, PHP cannot send any data to the client before using the header function.
Example 2:
in ASP
- <html><head> Head ><body>
- < %
- Response.Redirect ". /a.asp "
- Response.Redirect ". /b.asp "
- % >
- body> html>
The result is a redirected a.asp file.
What about PHP?
-
- Header ("Location:.. /a.php ");
- Header ("Location:.. /b.php ");
- ?>
- <html><head> head > < Body > body> html>
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
- Header ("...");
- Else
- {
- ...
- }
But we can simply use the following method:
- {Header ("..."); exit ();}
It is also important to note in PHP that if you are coding with Unicode (UTF-8), you will need to adjust your 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>
http://www.bkjia.com/phpjc/446416. HTML www.bkjia.com true http://www.bkjia.com/phpjc/446416.html techarticle We cannot have spaces between 1, location and ":", Otherwise, there will be an error. 2, before using the header can not have any output. 3, PHP code after using the header will also be executed. Here is the ...