Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What does 302 in php mean?

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

Most people do not understand the knowledge points of this article, so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "what php refers to" article.

In php, 302 is not an error, but a HTTP response status code, meaning "temporary redirect", indicating that the visited page is temporarily redirected to another page because of various needs; you can use header () to achieve 302 jump, syntax "header ('Location: jump url',true,302)".

Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

302 stands for temporary transfer (Temporarily Moved), and the HTTP response status code is not an error.

302 means temporary redirection, which means that the visited page is temporarily redirected to another page because of various needs.

In php, you can use header () to achieve 302 jumps.

There are two grammatical formats:

Syntax format 1:

Header ('HTTP/1.1 302 Moved Permanently'); header (' Location: https://www.yisu.com');)

Syntax format 2:

Header ('Location: https://www.yisu.com', true, 302)

By the way, if you want to adapt to HTTPS/HTTP, this is fine:

Header ('Location: / / www.yisu.com', true, 302)

Expand knowledge:

HTTP--3xx (redirect) response status code

Further action is required to complete the request. Typically, these status codes are used for redirection. Google recommends that you use redirects no more than 5 times per request. You can use the webmaster tool to see if Googlebot is having problems crawling redirected pages. The web crawl page under diagnostics lists the URLs that cannot be crawled by Googlebot due to redirection errors.

300 (multiple options): the server can perform a variety of actions for requests. The server can select an action based on the requestor (user agent), or provide a list of actions for the requestor to choose from.

301 (permanent Mobile): the requested web page has been permanently moved to a new location. When the server returns this response (the response to a GET or HEAD request), it automatically moves the requestor to a new location. You should use this code to tell Googlebot that a web page or Web site has been permanently moved to a new location.

302 (temporary Mobility): the server currently responds to requests from web pages in different locations, but the requester should continue to use the original location to respond to future requests. This code, similar to the 301 code that responds to get and head requests, automatically redirects the requestor to a different location, but it should not be used to tell googlebot that a web page or website has moved, as googlebot continues to crawl and index the original location.

303 (see other locations): the server returns this code when the requester should use separate get requests for different locations to retrieve the response. For all requests outside the head, the server automatically redirects to another location

304 (unmodified): the requested web page has not been modified since the last request. When the server returns this response, the web page content is not returned; if the web page has not changed since the requestor's last request, the server should be configured to return this response (called the if-modified-Since HTTP header). The server can tell googlebot that the web page has not changed since the last crawl, thereby saving bandwidth and overhead.

305 (use proxy): requesters can only use agents to access the requested web page. If the server returns this response, it also indicates that the requestor should use a proxy.

Server currently responds to web page requests from different locations, but the requester should continue to respond to future requests using the original location. This code is similar to the code that responds to get and head requests and automatically redirects the requestor to a different location, but should not tell googlebot that a page or website has moved, because googlebot will continue to grab the original location and index.

Seven uses of PHP header

1. Jump page

There is no space between header ('Location:'.$url); / / Location and':'.

two。 Declare content-type

Header ('content-type:text/html;charset=utf-8')

3. Returns the response status code

Header ('HTTP/1.1 404 Not Found')

4. Perform a jump after a certain period of time

Jump after header ('Refresh: 10; url= http://www.yisu.com/'); / / 10s).

5. Control browser caching

Header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header ("Last-Modified:". Gmdate ("D, d M Y H:i:s") "GMT"); header ("Cache-Control: no-cache, must-revalidate"); header ("Pragma: no-cache")

6.. Perform http verification

Header ('HTTP/1.1 401 Unauthorized'); header (' WWW-Authenticate: Basic realm= "Top Secret"')

7. Perform download operation

Header ('Content-Type: application/octet-stream'); / / set content type header (' Content-Disposition: attachment; filename= "example.zip'); / / set MIME user as attachment header ('Content-Transfer-Encoding: binary'); / / set transfer mode header (' Content-Length: '.filesize (' example.zip')) / / setting the content length above is the content of this article about "what is 302 in php". I believe everyone has a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to learn more about the relevant knowledge, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report