PHP 页面跳转的三种体式格局
第一种体式格局:header()
header()函数的主要功能是将HTTP协议标头(header)输出到浏览器。
语法:
void header ( string $string [, bool $replace = true [, int $http_response_code ]] )
可选参数replace指明是替代前一条相似标头照样增加一条雷同范例的标头,默以为替代。
相干引荐:《PHP入门教程》
第二个可选参数http_response_code强迫将HTTP响应代码设为指定值。 header函数中Location范例的标头是一种特别的header挪用,常用来完成页面跳转。注重:1.location和“:”号间不能有空格,不然不会跳转。
举例:
<html> <?php /* This will give an error. Note the output * above, which is before the header() call */ header('Location: http://www.example.com/'); exit; ?>
注重:
·header实行前不能有任何输出;
·location和:之间不能有空格;
·header后的php代码还会实行,所以须要注重运用exit。
第二种体式格局:meta标签
Meta标签是HTML中担任供应文档元信息的标签,在PHP顺序中运用该标签,也能够完成页面跳转。 若定义http-equiv为refresh,则翻开该页面时将依据content划定的值在肯定时间内跳转到响应页面。
< meta http-equiv="refresh" content="1;url=http:// www.baidu.com">
第三种体式格局:javascript
经由过程运用windows.location.href=‘url’; 是页面自动跳转到新的地点。
< ?php $url = "http://www.baidu.com"; echo "< script language='javascript' type='text/javascript'>"; echo "window.location.href='$url'"; echo "< /script>"; ?>
以上就是php中怎样跳转页面的细致内容,更多请关注ki4网别的相干文章!