Home  >  Article  >  Backend Development  >  What does php redirect mean?

What does php redirect mean?

青灯夜游
青灯夜游Original
2022-02-08 17:47:003224browse

In PHP, redirection refers to redirecting network requests to other locations through various methods; redirection can be divided into internal and external. The difference is that when external redirection occurs, the browser address The URL in the column will change.

What does php redirect mean?

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

php redirection

Redirect is to redirect various network requests to other locations through various methods. Divided into internal and external, the difference is that when external redirection occurs, the URL in the browser address bar will change.

Page redirection must have page jump, page jump does not necessarily have page redirection, that is to say, page redirection is really included in page jump, page redirection is page jump sufficient and unnecessary conditions.

When we are building a website, we often encounter situations that require web page redirection:

1. Website adjustment (such as changing the web page directory structure);

2. The web page is moved to a new address;

3. The web page extension is changed (if the application needs to change .php to .Html or .shtml).

In this case, if redirection is not done, the old address in the user's favorites or search engine database will only allow the visiting customer to get a 404 page error message, and the access traffic will be lost in vain; in addition, some registrations Websites with multiple domain names also need to redirect users who visit these domain names to automatically jump to the main site.

Summarize several methods of page jump under PHP

1. Meta tag implementation

Just add the following sentence in the head That’s it, jump to the target page after staying on the current page for 0 seconds

echo &#39;<meta http-equiv="refresh" content="0;url=https://www.baidu.com">&#39;;

2. JavaScript implementation

echo &#39;<script>window.location.href = &#39;https://www.baidu.com&#39;;</script>&#39;;

3. PHP page redirection implementation

header(&#39;Location: https://www.baidu.com&#39;);

Use PHP page The redirect jump is a little different from the above two methods in that its http response status code is specified as 3xx. The specific difference involves the HTTP request process, so I won’t go into details here.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What does php redirect mean?. 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