为你详解PHP页面跳转函数的具体含义
对于
PHP本身没有一个完全意义上的PHP页面跳转函数,也许Header函数算一个,但是,它只能用于页面的第一行。如果放在PHP页面的最后位置,除非前面的PHP没有输出任何字符,否则,会报错。
下面提供三种PHP自动页面跳转的方法,其一就是使用Header函数,其二则是使用HTML固有标记,当然,这个方法不仅仅可以应用于PHP,同样可以应用于ASP,.Net,以及Jsp中,第三种方法是输出Javascript,利用Js代码,达到PHP页面自动跳转的目的,同样的,这种方法也同样适用于PHP以外的其他语言,只是相应语言代码不同而已。
PHP页面跳转函数一、用HTTP头信息(Header函数)
也就是用PHP的HEADER函数。PHP里的HEADER函数的作用就是向浏览器发出由HTTP协议规定的本来应该通过WEB服务器的控制指令,例如声明返回信息的类型("Context-type: xxxx/xxxx"),页面的属性("No cache", "Expire")等等。
用HTTP头信息使PHP自动跳转到另外一个页面的方法如下:
<ol class="dp-xml"> <li class="alt"><span class="tag"> ?PHP </span></li> <li> <span>$</span><span class="attribute">url</span><span> = </span><span class="attribute-value">czbin</span><span>.</span>PHP<span> </span> </li> <li class="alt"><span>Header("HTTP/1.1 303 See Other"); </span></li> <li><span>Header("Location: $url"); </span></li> <li class="alt"><span>exit; </span></li> <li> <span class="tag">?></span><span> </span> </li> </ol>
注意一下,"Localtion:"后面有一个空格。
PHP页面跳转函数二、利用HTML标记(META中的REFRESH属性)
用HTML标记,就是用META的REFRESH标记,举例如下:
<ol class="dp-xml"> <li class="alt"><span class="tag"> ?PHP<span> $</span><span class="attribute">url</span><span> = </span><span class="attribute-value">czbin</span><span>.</span>PHP<span>;</span><span>?> </span></span></li> <li><span class="tag"><span> </span><span class="tag-name">HTML</span><span class="tag">></span><span> </span></span></li> <li class="alt"><span class="tag"><span> </span><span class="tag-name">HEAD</span><span class="tag">></span><span> </span></span></li> <li><span class="tag"><span> </span><span class="tag-name">META</span><span> </span><span class="attribute">HTTP-EQUIV</span><span>=</span><span class="attribute-value">"REFRESH"</span><span> <br></span><span class="attribute">CONTENT</span><span>="10; </span><span class="attribute">URL</span><span>=</span><span class="tag"><span> ? echo $url;</span><span class="tag">?></span><span class="tag">></span><span> </span></span></span></li> <li class="alt"><span class="tag"><span> /HEAD</span><span class="tag">></span><span> </span></span></li> <li><span class="tag"><span> </span><span class="tag-name">BODY</span><span class="tag">></span><span> </span></span></li> <li class="alt"><span class="tag"><span> /BODY</span><span class="tag">></span><span> </span></span></li> <li><span class="tag"><span> /HTML</span><span class="tag">></span><span> </span></span></li> </ol>
注:这里的CONTENT="10 的意思是说10秒以后跳转。
PHP页面跳转函数三、用JAVASCRIPT脚本来实现
举例如下:
<ol class="dp-xml"> <li class="alt"><span><span class="tag"></span>PHP<span><span> </span></span></span></li> <li> <span>$</span><span class="attribute">url</span><span>=</span><span class="attribute-value">czbin</span><span>.</span>PHP<span>; </span> </li> <li class="alt"><span>echo "<span class="tag"><span class="tag-name">SCRIPT</span><span> </span><span class="attribute">LANGUAGE</span><span>=</span><span class="attribute-value">"JavaScript"</span><span class="tag">></span><span>"; </span></span></span></li> <li> <span>echo "</span><span class="attribute">location.href</span><span>=</span><span class="attribute-value">'$url'</span><span>"; </span> </li> <li class="alt"> <span>echo "</span><span class="tag"><span class="tag-name">SCRIPT</span><span class="tag">></span><span>--</span><span class="tag">></span><span>"; </span></span> </li> <li> <span class="tag">?></span><span> </span> </li> </ol>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.
