Home > php教程 > php手册 > body text

php页面跳转与定时跳转页面方法

WBOY
Release: 2016-05-25 16:44:26
Original
808 people have browsed it

在php中页面跳转我们用到的是header函数了,如果要定时跳转页面我们就必须使用js或html了,下面我来给各位同学总结一下各种页面跳转的实现程序.

header()函数

 

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和":"号间不能有空格,否则不会跳转.

1.使用php里head函数进行跳转

注意:head跳转前不要有任何输出,不然可能不能跳转,代码如下:

header("refresh:3;url=http://www.phprm.com");//限时跳转 

header('location:http://www.phprm.com');//立即跳转 

2.HTML meta refresh 刷新与跳转(重定向)页面

Meta标签:Meta标签是HTML中负责提供文档元信息的标签,在PHP程序中使用该标签,也可以实现页面跳转,若定义http-equiv为refresh,则打开该页面时将根据content规定的值在一定时间内跳转到相应页面.

refresh 属性值 — 刷新与跳转(重定向)页面

refresh用于刷新与跳转(重定向)页面

refresh出现在http-equiv属性中,使用content属性表示刷新或跳转的开始时间与跳转的网址,代码如下:

3.js实现页面跳转

js实现跳转主要用到location对象,代码如下:

<script type=&#39;text/javascript&#39;> 
 // 立即跳转 
 window.location.href = &#39;http://www.phprm.com&#39;; 
 // 限时跳转 
 setTimeout(function(){ 
  // 3秒后跳转 
  window.location.href = &#39;http://www.phprm.com&#39;; 
 },3000); 
</script>
Copy after login


文章网址:

随意转载^^但请附上教程地址。

Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!