Home > Backend Development > PHP Tutorial > php怎么实现页面跳转?

php怎么实现页面跳转?

PHPz
Release: 2020-06-13 15:47:05
Original
1569 people have browsed it

php怎么实现页面跳转?

php实现页面跳转的几种方式

1、使用header()函数

<?php
  header("location:url地址");
?>
Copy after login

例如

<?php
  header("location:helloworld.php");
?> 
//页面会立即跳转,因为header执行了location重定向
Copy after login

延迟跳转(比如登陆成功后会有几秒钟等待时间,然后跳转到了其他页面)

<?php
  header("Refresh:秒数;url=地址");
?>
Copy after login

例如

 <?php
    header("Refresh:3;url=helloworld.php");
 ?>
Copy after login

会在3秒后执行跳转<?php sleep(3); header("location:url地址")?> 调用了sleep()方法,效果也是x秒后执行跳转

2、输出js代码,使用window.location.href来跳转

<?php
echo "<script>window.location.href=&#39;//m.sbmmt.com&#39;</script>";
?>
Copy after login

3、输出

<?php
echo "<meta charset=&#39;UTF-8&#39; http-equiv=&#39;refresh&#39; content=&#39;2;url=//m.sbmmt.com&#39;>";
?>
Copy after login

更多相关知识,请访问 PHP中文网!!

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