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

php怎么实现页面跳转?

PHPz
PHPzOriginal
2016-06-13 11:28:201579browse

php怎么实现页面跳转?

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

1、使用header()函数

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

例如

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

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

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

例如

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

会在3秒后执行跳转4f268512b0ad509f21839988b1a29813  调用了sleep()方法,效果也是x秒后执行跳转

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

<?php
echo "<script>window.location.href=&#39;http://www.php.cn&#39;</script>";
?>

3、输出e8e496c15ba93d81f6ea4fe5f55a2244

<?php
echo "<meta charset=&#39;UTF-8&#39; http-equiv=&#39;refresh&#39; content=&#39;2;url=https://www.php.cn&#39;>";
?>

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

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