PHP jump
| The code is as follows: |
Copy code |
|
<? Php
Header ("location: http://www.111cn.net ");
?> |
Header function usage
PHP page Jump 1. header () function
The header () function is a very simple method for page jump in PHP. The main function of the header () function is to output the HTTP header to the browser.
The header () function is defined as follows:
Void header (string [, bool replace [, int http_response_code]) the optional parameter replace specifies whether to replace the previous header or add a header of the same type, which is replaced by default.
The second optional parameter http_response_code sets the HTTP code as the specified value. The Location header in the header function is a special header call, which is often used to redirect pages. Note: 1. There cannot be spaces between location and:. Otherwise, no jump will be made.
2. There cannot be any output before using the header.
3. The PHP code after the header will also be executed. For example, redirect a browser to a Guanwei blog
| The code is as follows: |
Copy code |
|
<? Php
// Redirect the browser
Header ("Location: http://www.111cn.net ");
// Ensure that subsequent code will not be executed after redirection
Exit;
?> |
PHP page jump 2. Meta tag
Meta tag is the tag that provides document Meta information in HTML. You can use this tag in a PHP program to redirect pages. If http-equiv is defined as refresh, the page will be redirected to the corresponding page within a certain period of time based on the value specified by content.
If you set content = "seconds; url = url", it defines how long the page will jump to the specified url. For example, after the meta tag is used to implement the vaccine, the page automatically jumps to the Guanwei blog.
| The code is as follows: |
Copy code |
|
<Meta http-equiv = "refresh" content = "1; url = http://www.111cn.net"> |
For example, the following meta. php program automatically jumps to www.111cn.net after one second of staying on the page.
| The code is as follows: |
Copy code |
|
<? Php
$ Url = "http://www.111cn.net";?>
<Html>
<Head>
<Meta http-equiv = "refresh" content = "1; url = <? Php echo $ url;?> ">
</Head>
<Body>
The page stays for only one second ......
</Body>
</Html> |
PHP page jump 3. JavaScript (common and recommended)
For example, this code can be placed in any legal position in the program.
| The code is as follows: |
Copy code |
|
<? Php
$ Url = "http://www.111cn.net ";
Echo "<script language = 'javascript 'type = 'text/javascript '> ";
Echo "window. location. href = '$ url '";
Echo "</script> ";
?> |
Some js jump methods are provided.
JavaScript jump
Method 1:
| The code is as follows: |
Copy code |
<Script language = "javascript">
Window. location = "http://www.111cn.net ";
</Script> |
Method 2:
| The code is as follows: |
Copy code |
|
<Script language = "javascript">
Document. location = "http://www.111cn.net ";
</Script> |
ASP redirection
| The code is as follows: |
Copy code |
|
<%
Response. redirect "http://www.111cn.net"
%> |