在之前的文章中我们介绍了php中header函数,以及header的定义,在php中header有很多种使用方式,今天我们就为大家介绍php中header方法实现页面跳转的案例、
本文实例分析了php页面跳转操作。分享给大家供大家参考,具体如下:
跳转
header()为php函数,向浏览器发送指定命令
html:
<meta http-equiv="refresh" content="3;url=other.php"/>
立即跳转:
header('location:other.php');
//file_put_contents('bee.txt','execute');
die;
执行header时候,并不是立即结束,而是会把页面执行完毕;在header前面不能有任何输出,若有开启输出缓冲则不提示错误,php.ini->output_buffering = 4096|off
提示跳转:
header('refresh:3,url=other.php');
echo '3s 后跳转';
//由于只是普通页面展示,提示的样式容易定制
die;
封装的跳转函数:
/*
*跳转
*@param $url 目标地址
*@param $info 提示信息
*@param $sec 等待时间
*return void
*/
function jump($url,$info=null,$sec=3)
{
if(is_null($info)){
header("location:$url");
}else{
// header("refersh:$sec;url=$url");
echo"<meta http-equiv=\"refresh\" content=".$sec.";url=".$url.">";
echo $info;
}
die;
}
总结:
php页面跳转操作,结合实例形式对比分析了html跳转与php使用header方法跳转的相关操作技巧与注意事项,并给出了一个跳转的封装函数供大家参考!
相关推荐:
php中header函数的作用分析
php中关于header头部定义的详解
php header失效的原因分析及解决方法
以上就是php中header方法实现页面跳转的详细内容。