php中重定向网页跳转方法总结案例教程

吾爱主题 阅读:126 2021-11-23 15:59:00 评论:0

PHP中重定向网页跳转页面的方法(共三种)

第一种:利用header()函数进行重定向,这也是我用的较多的。(注意!locationhe和“:”之间不能有空格,否则无作用!)

?
1 2 3 4 5 <?php      header('content-type:text/html;charset=uft-8);      //重定向页面      header( 'location:index.php' );   ?>

第二种:利用HTML 头部中的 meta标签,定义http-equiv=refresh 和content=”跳转花费的时间(秒为单位);url=跳转地址”

?
1 2 3 4 5 6 7 8 <!DOCTYPE html> < html lang = "en" > < head >      < meta charset = "UTF-8" >      //跳转页面,跳转时间:3秒钟,目标地址:index.php      < meta http-equiv = "refresh" content = "3;url=index.php" >      < title >skip...</ title > </ head >

或者

?
1 2 3 4 5 6 7 8 9 10 11 12 <?php header( 'content-type:text/html;charset=utf-8' ); $url = 'index.php' ;   ?>   <!DOCTYPE html> <html lang= "en" > <head>      <meta charset= "UTF-8" >      //跳转页面,跳转时间:2秒钟,目标地址:index.php      <meta http-equiv= "refresh" content= "2;url=<?php echo $url; ?>" >      <title>skip...</title> </head>

第三种:利用javascript进行跳转

?
1 2 3 4 5 6 <?php header( 'content-type:text/html;charset=utf-8' ); $url = 'index.php' ; //立即跳转至目标页面 echo <script>window.location.href= '$url' ;</script>; ?>

以上就是PHP中重定向页面的三种方法。

到此这篇关于php中重定向网页跳转方法总结案例教程的文章就介绍到这了,更多相关php中重定向网页跳转内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://blog.csdn.net/YAruli/article/details/78837240

可以去百度分享获取分享代码输入这里。
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

【腾讯云】云服务器产品特惠热卖中
搜索
标签列表
    关注我们

    了解等多精彩内容