PHP program Development Three ways to achieve page jumpsApril 16, 2017 20:44:14Hits: 3352PHP is currently the preferred language for developing Web projects. In Web projects, jumping from one Web page to another is one of the most common techniques. The user clicks the link, the button or the system logic and so on all need to implement the page jumps. This paper introduces the method of automatic page jump in PHP development.
Way One: header () Implementation 301 redirect
- <?php
- Header ("http/1.1 301 Moved permanently");
- Header ("location:http://www.ailab.cn/");
- ?>
The header () function is a very simple way to jump a page in PHP. The main function of the header () function is to output the HTTP protocol header (header) to the browser.
The header () function is defined as follows:
void header (String string [, bool replace [, int http_response_code]])
The optional parameter, replace, indicates whether to replace the previous similar header or to add a header of the same type, which is replaced by default.
The Second optional parameter, Http_response_code, forces the HTTP corresponding code to be set to the specified value. The header of the location type in the header function is a special header call that is commonly used to implement page jumps. Note: There can be no spaces between location and ":", otherwise it will not jump.
Way two: Meta tags
The META tag is the tag in HTML that is responsible for providing the meta-information of the document, which can be used in a PHP program or a page jump. If you define HTTP-EQUIV as refresh, the page will be opened to the appropriate page for a certain amount of time based on the values specified in the content.
If you set content= "seconds; url= url", you define how long it takes for the page to jump to the specified URL.
- <Meta http-equiv="Refresh" content= "3; Url=/http
- www.ailab.cn/">
For example, the following program implements the page to automatically jump to the specified page after 3 seconds of stay in the page.
- <html>
- <head>
- <meta http-equiv="Refresh" content= "3; url=http://www.ailab.cn ">
- </head>
- <body> page only stays for 3 seconds ... </Body>
- </html>
Method Three: Construct JavaScript to implement jump
For example, this code can be placed in the program to jump to the page.
- <?php
- echo "<script language= ' javascript ' type= ' text/javascript ' >window.location.href= ' http://www.ailab.cn/'; </script> "; ?>
PHP program development to implement the page jump