php如何实现页面跳转

今天在写程序时,遇到页面跳转问题,总结下来,方便以后查看:

1.header函数实现跳转

<?php
header("Location:jump.php");//重定向浏览器 
exit(); //确保重定向后后面的代码不会执行

?>

 注意一下三个方面:1.location和“:”号间不能有空格,否则不会跳转。

         2.在用header前不能有任何的输出。

         3.header后的PHP代码还会被执行。

2.meta标签

<?php
   $url = "http://www.baidu.com"; 
?>
 <html>   
 <head>   
 <meta http-equiv="refresh" content="5;  url=<?php echo $url;?>"> 
 <meta http-equiv="Content-Type" content="text/html; charset=gb2312">  
 </head>   
 <body>   页面只停留5秒……   
 </body>
 </html>  

 3.javascript实现跳转

< ?php 
 $url = "http://www.baidu.com"; 
 echo "< script language='javascript' type='text/javascript'>"; 
 echo "window.location.href='$url'";  echo "< /script>"; 
 ?> 

例如,此代码可以放在程序中的任何合法位置。

这三种方式都可以实现页面跳转,很实用哦。

千里之行,始于足下。改变现在,就是改变未来。改变未来,从现在开始。 个人网站:http://www.wangkongming.cn
原文地址:https://www.cnblogs.com/wangkongming/p/2724908.html