How to implement redirection in php

藏色散人
Release: 2023-03-09 08:54:02
Original
1605 people have browsed it

How to implement page redirection in php: 1. Use HTTP header information to redirect to another page; 2. Use META's REFRESH tag to implement redirection; 3. Implement redirection through scripts.

How to implement redirection in php

The operating environment of this article: Windows7 system, PHP7.1 version, DELL G3 computer

How does php implement redirection to the page?

1. Use HTTP header information

That is, use PHP’s HEADER function. The function of the HEADER function in PHP is to issue control instructions to the browser that should be passed through the WEB server specified by the HTTP protocol, such as declaring the type of return information ("Context-type: xxx/xxx"), the attributes of the page ("No cache", "Expire"), etc.

The method of redirecting to another page using HTTP header information is as follows:

<?
Header("Location: http://www.baidu.com");
?>
Copy after login

Note that there is a space after "Localtion:".

2. Use HTML tags

Use HTML tags, that is, use REFRESH tags of META. For example:

<? if (!isset($url)) exit;?>
<HTML>
<HEAD>
<META HTTP-EQUIV="REFRESH" CONTENT="5; URL=<? echo $url;?>>
</HEAD>
<BODY>
</BODY>
</HTML>
Copy after login

3. Use scripts to implement

Examples are as follows:

<?
$url="http://www.baidu.com";
echo "<script type="text/javascript">";
echo "location.href=’$url’";
echo "</script>";
?>
Copy after login

[Recommended learning: PHP video tutorial]

The above is the detailed content of How to implement redirection in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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