There are multiple methods for page jump. First, we will introduce the built-in function implementation methods in PHP, mainly using headers (there are multiple methods for page jump. First, we will introduce the built-in function implementation methods in PHP, mainly using the header () function.
The main function of the header () function is to output the HTTP header to the browser.
Syntax
Header (string, replace, http_response_code)
The parameter description string is required. Specifies the header string to be sent. Replace is optional. Indicates whether the header replaces the previous header or adds the second header. The default value is true (replace ). False (multiple headers of the same type are allowed ). Http_response_code is optional. Forces the HTTP response code to the specified value. (PHP 4 and later versions are available)
Tips and comments
Note: After PHP 4.4, this function prevents multiple headers from being sent at a time. This is a protection against header injection attacks.
Code:
<? Php // redirect the browser header ("Location: https://www.php1.cn"); // make sure the subsequent code is not executed after the redirection;?>
<? Php // redirect to the header ("Location: news. php") on the news. php page; // make sure that the code will not be executed after the redirection;?>
Note:
This function takes effect only when you change the PHP. ini file. Find the configuration file php. ini, and then find the item: output_buffering, change its value from off to on, and restart Apache.
Appendix (two other jump implementation methods ):
Method 1: Use Meta tags
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.
< meta http-equiv="refresh" content="1;url=https://www.php1.cn">
For example, the following meta. php program automatically jumps to the ph Chinese network after one second of staying on the page.
Method 2: Use JS
<? Phpecho"