Home  >  Article  >  Backend Development  >  Several common URL address jump methods for PHP headers

Several common URL address jump methods for PHP headers

小云云
小云云Original
2017-11-11 15:42:473369browse

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...

Several common URL address jump methods for PHP headers


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.

>

##

The page only stays for one second


PHP page jump 3. javascript (commonly used, recommended)

For example, this code can be placed in any legal position in the program.


$url = "http://www.guanwei.org";

echo "";


?>

In addition to these methods, I believe everyone also has their own methods. We have introduced many articles about PHPheader to you before. You can pay attention to the PHP Chinese website for reference.

Related recommendations:

Some usage of PHP header function

PHP uses header to set browser cache

Summary of HTTP protocol usage used by header in php


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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn