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 indicates whether to replace the previous header or add a header of the same type. The default parameter is replace.
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.
1. Jump using the head function in php
Note: do not have any output before the head jump, or you may not be able to jump.
The code is as follows: |
Copy code |
Header ("refresh: 3; url = http://www.111cn.net"); // time-limited jump Header ('Location: http://www.111cn.net '); // jump now |
2. HTML meta refresh and redirect page
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.
Refresh property value-refresh and redirect page
Refresh is used to refresh and redirect pages.
Refresh appears in the http-equiv attribute. The content attribute is used to indicate the start time of refresh or redirect and the URL to jump.
The code is as follows: |
Copy code |
<Meta http-equiv = "refresh" content = "3; url = http://www.111cn.net"> |
3. js page jump
Js redirection mainly uses location objects.
The code is as follows: |
Copy code |
<Script type = 'text/javascript '> // Jump now Window. location. href = 'http: // www.111cn.net '; // Time-limited jump SetTimeout (function (){ // Jump 3 seconds later Window. location. href = 'http: // www.111cn.net '; },3000 ); </Script> |