PHP is the preferred language for WEB development by many programmers. In actual development, all the functions of the website can be met by compiling in PHP, such as PHP page jump. ? In a Web system, redirecting from one Web page to another is one of the most commonly used technologies in LAMP projects. Page jump may be caused by the user clicking a link or button, or automatically generated by the system. This section describes common methods for automatically page redirect in PHP. 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 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. 2. there cannot be any output before using the header. 3. the PHP code after the header will also be executed. For example, redirect the browser to the official forum of the lamp brothers.
- <?? Php?
- // Redirect the browser?
- Header ("Location :? Http://bbs.lampbrother.net ");?
- // After the redirection is ensured, the subsequent code will not be executed?
- 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, the page automatically jumps to the LAMP Brothers' official forum after the meta tag is used to implement the vaccine.
- <?meta?http-equiv="refresh"?
- content="1;url=http://bbs.lampbrother.net">?
? For example, the following meta. php program automatically jumps to bbs.lampbrother.net after one second of staying on the page.
- <?? Php? ?
- $ Url? =? "Http://bbs.lampbrother.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 For example, this code can be placed in any legal position in the program.
- <??php ?
- $url?=?"http://bbs.lampbrother.net"; ?
- echo?"<?script?language='javascript'?
- type='text/javascript'>"; ?
- echo?"window.location.href='$url'"; ?
- echo?"<?/script>"; ?
- ?>?
The above are the three PHP page jump implementation methods we will introduce to you. |