Home > Article > Backend Development > Several common URL address jump methods for PHP headers
The PHP header function is a function that programmers will definitely use, so this article will continue to explain several methods for commonly used URL address jumps in PHP header. Regardless of the method of URL jump in php, it is inseparable from the header function. Below I will sort out some commonly used URL jump implementation procedures and precautions. Friends in need can refer to it...
No matter which method you use to jump URLs in PHP, you cannot do without the header function. Below I will sort out some common URL jump implementation procedures and precautions for you. , friends in need can refer to it.
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 protocol header (header) to the browser.
The definition of the header() function is as follows:
void header (string string [,bool replace [,int http_response_code]])
The optional parameter replace indicates to replace the previous similar header The header still adds a header of the same type, and the default is replacement.
The second optional parameter http_response_code forces the HTTP corresponding code to the specified value. The Location type header in the header function is a special header call, often used to implement page jumps. Note: There cannot be a space between
1.location and the ":" sign, otherwise it will not jump.
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 linzl.com
//Redirect the browser
header("Location: http://www.111cn.net");
//Ensure that after redirection, subsequent code will not be executed
exit;
?>
PHP page jump 2. Meta tag
The Meta tag is a tag in HTML that is responsible for providing document meta-information. Using this tag in a PHP program can also achieve page jumps.
If http-equiv is defined as refresh, when the page is opened, it will jump to the corresponding page within a certain period of time based on the value specified by the content.
If you set content="seconds"; url="website", it defines how long it will take for the page to jump to the specified URL.
For example, the following program meta.php implements the page to automatically jump to www.guanwei.org after staying on the page for one second.
>
Some usage of PHP header function
PHP uses header to set browser cache
The above is the detailed content of Several common URL address jump methods for PHP headers. For more information, please follow other related articles on the PHP Chinese website!