Three ways to implement redirection in php

伊谢尔伦
Release: 2016-11-26 14:04:21
Original
1162 people have browsed it

1. Use PHP’s header function

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 using HTTP header information to redirect PHP to another page is as follows:

<?php 
    $url = "www.yaojinbu.com";  
    if (!empty($url))    
    {    
        header("HTTP/1.1 303 See Other"); //这条语句可以不写  
        header("Location: $url");  
    }    
?>
Copy after login

Note: There is a space after "Localtion:".

2. Use HTML meta tag

Use HTML tag, that is, use META REFRESH tag, for example:

<?php 
    if (!empty($url))  
    {  
        echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0;URL=$url\">";  
    }  
?>
Copy after login

3. Use JavaScript script function

For example:

<?php 
    if (isset($url))  
    {  
        echo "<SCRIPT LANGUAGE="JavaScript">";  
        echo "location.href=&#39;$url&#39;";  
        echo "</SCRIPT>";  
    }  
?>
Copy after login

or

<?php echo "<script>window.location =\"$url\";</script>";?>
Copy after login


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