PHP页面跳转一、header()函数
PHP跳转页面的三种方式
转载header()函数是PHP中进行页面跳转的一种十分简单的方法。header()函数的主要功能是将HTTP协议标头(header)输出到浏览器。
header()函数的定义如下:
void header (string string [,bool replace [,int http_response_code]])
可选参数replace指明是替换前一条类似标头还是添加一条相同类型的标头,默认为替换。
第二个可选参数http_response_code强制将HTTP相应代码设为指定值。 header函数中Location类型的标头是一种特殊的header调用,常用来实现页面跳转。注意:1.location和“:”号间不能有空格,否则不会跳转。
2.在用header前不能有任何的输出。
3.header后的PHP代码还会被执行。例如
view plaincopy to clipboardprint?
< ?php
//重定向浏览器
header("Location: http://blog.csdn.net/abandonship");
//确保重定向后,后续代码不会被执行
exit;
?>
< ?php
//重定向浏览器
header("Location: http://blog.csdn.net/abandonship");
//确保重定向后,后续代码不会被执行
exit;
?>
PHP页面跳转二、Meta标签
Meta标签是HTML中负责提供文档元信息的标签,在PHP程序中使用该标签,也可以实现页面跳转。若定义http-equiv为refresh,则打开该页面时将根据content规定的值在一定时间内跳转到相应页面。若设置content="秒数;url=网址",则定义了经过多长时间后页面跳转到指定的网址。
< meta http-equiv="refresh" content="1;url=http://blog.csdn.net/abandonship">
例,以下程序meta.php实现在该页面中停留一秒后页面自动跳转。
view plaincopy to clipboardprint?
<?php
$url = "http://blog.csdn.net/abandonship";
?>
<html>
<head>
<meta http-equiv="refresh" content="1;url=<?php echo $url; ?>">
</head>
<body>
Its transit station.
</body>
</html>
<?php
$url = "http://blog.csdn.net/abandonship";
?>
<html>
<head>
<meta http-equiv="refresh" content="1;url=<?php echo $url; ?>">
</head>
<body>
Its transit station.
</body>
</html>
PHP页面跳转三、JavaScript
view plaincopy to clipboardprint?
<?php
$url = "http://blog.csdn.net/abandonship";
echo "<script type=text/javascript>";
echo "window.location.href=$url";
echo "</script>";
?>
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
ASP三种页面跳转方式比较
度慢是其最大缺陷...
数据 客户端 服务器端 -
php跳转的三种方法
方法一:使用PHP自带函数Header("Location:网址");说明:必须在网页没有任何输出的时候执行,要特别要注意空格。方法
php javascript ViewUI PHP -
springmvc跳转到自定义错误页面的三种方法
有时候我们并不想跳转到系统自定义的错误页面中,那么我们需要自定义页面并且实现它的跳转 有三种方法可以实现 方法一:最简单的实现,也是最快的 在web.xml下配置如下:
ssm springmvc 自定义 jsp页面 xml