MENU

PHP实现页面跳转小记

August 20, 2022 • Read: 596 • PHP,HTML

  • 一句话式
<?php $url = $_GET['url']; 
Header("Location:$url"); 
?>
  • IF 条件判断
if($_COOKIE["u_type"]){ 
    header('location:register.php'); 
} 
else{ 
   setcookie('u_type','1','86400*360');//设置cookie长期有效 
    header('location:zc.html'); 
}
  • JavaScript 式
<?php $url=czbin.php; 
echo "<!--<SCRIPT LANGUAGE="javascript">"; 
echo "location.href='$url'"; 
echo "</SCRIPT>-->"; 
?>
  • HTML 标记式(meta 的 REFRESH 属性)
<HTML> 
  <HEAD> 
    <META HTTP-EQUIV="REFRESH" CONTENT="10"; URL=www.php.cn/> 
  </HEAD> 
</HTML>
  • HTTP 头信息(Header 函数)式
<?php 
$url = czbin.php 
Header("HTTP/1.1 303 See Other"); 
Header("Location: $url"); 
exit;  
?>

文章来源

Last Modified: August 23, 2022
Archives QR Code Tip
QR Code for this page
Tipping QR Code