search
Homephp教程php手册php常见的页面跳转方法汇总

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输出,哪怕是一个空格.那么在页顶会显示错误信息..

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools