header() 301 redirection implementation code_PHP tutorial

WBOY
Release: 2016-07-20 11:02:29
Original
1330 people have browsed it

Let’s look at an example first,

header('location: http://www.111cn.cn/');

The above is a simple jump. How do we make a permanent redirection? as follows.


Grammar
header(string,replace,http_response_code) parameter description
string required. Specifies the header string to be sent.
replace optional. Indicates whether this header replaces the previous header, or adds a second header.

Default is true (replacement). false (allow multiple headers of the same type).

http_response_code Optional. Force the http response code to the specified value. (php tutorial 4 and above available)


Among others, http_response_code is the 301 code we want to write, as follows.


$url = "http://www.zhutiai.com";
header("http/1.1 301 moved permanently");
header("location: $url");
exit();

Note: From php 4.4 onwards, this function prevents multiple headers from being sent at once. This is a protection measure against header injection attacks.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445357.htmlTechArticleLet’s first look at an example, header(location: http://www.111cn.cn/); The above is A simple jump, how do we make a permanent redirection. as follows. Syntax header(string,replace,http_respo...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!