PHP function header () for page jump

Source: Internet
Author: User
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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.