Home >Backend Development >PHP Problem >How to implement URL jump in php
How to implement URL jump in php: 1. Use "Header("Location:$url");" to implement the jump; 2. Use the if judgment to implement the jump; 3. Use "echo " The location.href='$url'";" method implements jumps and so on.
The operating environment of this tutorial: Windows 7 system, PHP version 5.6. This method is suitable for all brands of computers.
Recommended: "PHP Video Tutorial"
Common PHP implementation URL address jump code
1. PHP jump code in one sentence:
<?php $url = $_GET['url']; Header("Location:$url"); ?>
Note: If saved as ad.php, you can achieve the effect of ad.php?url=www.baidu.com jumping to Baidu.com
2. PHP jump code if judgment:
if($_COOKIE["u_type"]){ header('location:register.php'); } else{ setcookie('u_type','1','86400*360');//设置cookie长期有效 header('location:zc.html'); }
Note: Save it as zc.php. When the user visits zc.php, it will judge whether a cookie exists. If it exists, jump to register.php. If it does not exist, it will jump to register.php. Then create a cookie and jump to zc.html
3. PHP jump code javascript format:
<?php $url=czbin.php; echo "<!--<SCRIPT LANGUAGE="javascript">"; echo "location.href='$url'"; echo "</SCRIPT>-->"; ?>
4. PHP jump code HTML markup format (REFRESH attribute of META):
<HTML> <HEAD> <META HTTP-EQUIV="REFRESH" CONTENT="10"; URL=www.baidu.com/> </HEAD> <BODY> </BODY> </HTML>
Note: CONTENT="10" here means to jump after 10 seconds.
5. PHP jump code HTTP header information (Header function) formula:
<?php $url = czbin.php Header("HTTP/1.1 303 See Other"); Header("Location: $url"); exit; ?>
This method is suitable for all brands of computers.
The above is the detailed content of How to implement URL jump in php. For more information, please follow other related articles on the PHP Chinese website!