Home  >  Article  >  Backend Development  >  How to redirect url in php

How to redirect url in php

王林
王林Original
2019-12-04 09:17:284554browse

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>34934661d7147ca926b095899343bad0 before the tag.

Example:

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

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>

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>

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!

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