Method 1: Use PHP built-in functions
Header ("location: URL
");
Note: It must be executed when the webpage does not have any output. Pay special attention to spaces. For the space removal method, refer to 4th. That is, this sentence will go wrong when it is placed in the body or behind the webpage at the beginning, Method 2: Use Meta Echo "<meta http-equiv = Refresh content = '0; url = URL '> "; Note: There is no limit on method 1, but if there is an output in front, the output content will flash and enter the jump page. For example: $ Post = "Guoqing. php? Id = ". urlencode (" $ id ")." & name = ". urlencode ($ name ); // The urlencode () function does not display the actual Chinese content of the $ a variable in the address bar. Use % ...... % ...... . Echo "<meta http-equiv = Refresh content = '0; url = $ Post'>"; // page Jump statement to realize page value transfer
Method 3: use JavaScript Echo "<script language = 'javascript '> "; Echo "location = 'URL ';"; Echo "</SCRIPT> "; |
4: Why do I get only the first half when I send a variable to another web page, and all the variables starting with a space are lost?
Code:
<?
PHP
$ VaR
=
"Hello PHP"
;
// Change it to $ Var = "Hello PHP"; What are the results?
$ Post
=
"Receive. php? Name ="
.
$ VaR
;
Header
(
"Location: $ Post"
);
?>
A very comprehensive PHP Technology website for PHP enthusiasts
Http://www.phpfans.net
There are quite a variety of articles and source code.
Content of receive. php:
Code:
<?
PHP
Echo
"<pre>"
;
Echo
$_GET
[
"Name"
];
Echo
"</pre>"
;
?>
A very comprehensive PHP Technology website for PHP enthusiasts
Http://www.phpfans.net
There are quite a variety of articles and source code.
The correct method is:
Code:
<?
php
$Var
=
"hello php"
;
$post
=
"receive.php?Name="
.
urlencode
(
$Var
);
header
(
"location:$post"
);
?>
PHP enthusiast site
Http://www.phpfans.net
Provide all information for phper.
You do not need to use urldecode () on the receiving page. The variable is automatically encoded.
When using header ("Location: Test. php") in PHP to redirect, pay attention to the following points:
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.
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
<HTML> <% Response. Redirect ".../test. asp" %>
</Body> The following code in PHP reports an error:
<HTML> <?
Header ("Location: ../test. php ");
?>
</Body> You can only do this:
<?
Header ("Location: ../test. php ");
?>
<HTML> That is, the header function cannot send any data to the customer.
Example 2:
ASP
<HTML> <%
Response. Redirect ".../a. asp"
Response. Redirect ".../B. asp"
%>
</Body> The result is to redirect the. asp file.
What about PhP?
<?
Header ("Location: ../a. php ");
Header ("Location: ../B. php ");
?>
<HTML> 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.
<% @ Language = "VBScript
"CodePage =" 936 "%>
<% If request. servervariables ("SERVER_NAME") = "news.sina.com" then
Response. Redirect "News/index.htm"
Else %>
<% End if %>
<SCRIPT>
VaR url = location. href;
If (URL. indexof ('HTTP: // www.zqpc.net.cn /')! =-1) location. href = '/index/index.htm ';
If (URL. indexof ('HTTP: // www.zqtj.net /')! =-1) location. href = '/index1/index.htm ';
If (URL. indexof ('HTTP: // www.xxfww.net.cn /')! =-1) location. href = '/CN/index. asp ';
If (URL. indexof ('HTTP: // xxfww.net.cn /')! =-1) location. href = '/CN/index. asp ';
</SCRIPT>