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

php常见的页面跳转方法汇总

WBOY
Release: 2016-06-13 09:07:01
Original
772 people have browsed it

php常见的页面跳转方法汇总

 在php编写中有时会用户页面跳转,在这里收集了几种不错的跳转方法,可以用到。

用HTTP头信息实现

也就是用PHP的HEADER函数。PHP里的HEADER函数的作用就是向浏览器发出由HTTP协议规定的本来应该通过WEB服务器的控制指令,例如声明返回信息的类型("Context-type: xxx/xxx"),页面的属性("No cache", "Expire")等等。
用HTTP头信息重定向到另外一个页面的方法如下:

 

代码如下:



if (isset($url))
{
Header("HTTP/1.1 303 See Other");
Header("Location: $url");
exit; //
}
?>

 

用HTML标记

用HTML标记,就是用META的REFRESH标记,举例如下:

 

代码如下:


if (!isset($url)) exit;?>




$url="http://www.3LIAN.net";
echo "";
?>

 

利用html特性

 

代码如下:


echo " ";

 

其中:XX是秒数,0为立即跳转.refresh 是刷新的意思.Url 是要跳转到的页面.

利用script实现

 

 代码如下:


echo '<script>url="submit.php";window.location.href=url;</script>';

 

另一种利用script实现

利用script实现,所不同的是使用 open 语句.且可以限制原窗口还是父窗口,子窗口或者新窗口.

 

 代码如下:


<script>url="submit.php";window.open(\'url,\'\',\'_self\');</script>

 

其中 更改\'_self\' 就可以实现跳转限制原窗口还是父窗口,子窗口或者新窗口.第七种:利用php自带函数发送头部信息

 

代码如下:


header("Location: Url");

 

速度最快,功能强大...但是有个问题必须指出:如果在使用这个函数前已经有html输出,哪怕是一个空格.那么在页顶会显示错误信息..

Related labels:
php
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!