Home > Backend Development > PHP Problem > How to redirect url in php

How to redirect url in php

王林
Release: 2023-02-28 16:54:01
Original
4630 people have browsed it

How to redirect url in php

1. Use the header() function

PHP’s HTTP related functions provide a header() function. First of all, you must be clear that header( ) function must be placed at the beginning of the php program, and no other header() function or setcookie() can be called before. If it is with web page output, this statement must be placed &lt ;HEAD></HEAD> before the tag.

Example:

<? 
header("location: http://www.baidu.com"); 
exit; 
?>
Copy after login

As long as this statement is executed, the webpage will be automatically redirected

Online video tutorial recommendation:php video tutorial

2. Use HTML tags to redirect

Example:

<HTML> 
<HEAD> 
<? 
if(isset($url)) 
{ 
echo "<META HTTP-EQUIV=\"refresh\" CONTENT=\"5;url=$url\">"; 
} 
?> 
</HEAD> 
<BODY> 
</BODY> 
</HTML>
Copy after login

CONTENT="5;url=$url" means that after 5 seconds, this webpage will Automatically redirect to the address $url.

3. Use js script to implement redirection

Example:

<html> 
<? 
$url="http://www.bibias.com"; 
echo "<script language=\"javascript\">"; 
echo "location.href=\"$url\""; 
echo "</script>"; 
?> 
</html>
Copy after login

Recommended related articles and tutorials: php tutorial

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

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