在php中要实现跳转有很多方法,最常规的跳转方法就是使用header函数来操作了,当然也可以在php中输入js跳转形式,下面我来给大家介绍一下。
PHP 跳转
代码如下 | 复制代码 |
header("location: http://www.111cn.net"); |
header函数使用
PHP页面跳转一、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和“:”号间不能有空格,否则不会跳转。
2.在用header前不能有任何的输出。
3.header后的PHP代码还会被执行。例如,将浏览器重定向到冠威博客
代码如下 | 复制代码 |
//重定向浏览器 |
PHP页面跳转二、Meta标签
Meta标签是HTML中负责提供文档元信息的标签,在PHP程序中使用该标签,也可以实现页面跳转。 若定义http-equiv为refresh,则打开该页面时将根据content规定的值在一定时间内跳转到相应页面。
若设置content=”秒数;url=网址”,则定义了经过多长时间后页面跳转到指定的网址。例如,使用meta标签实现疫苗后页面自动跳转到冠威博客。
代码如下 | 复制代码 |
例如,以下程序meta.php实现在该页面中停留一秒后页面自动跳转到www.111cn.net。
代码如下 | 复制代码 |
$url = "http://www.111cn.net"; ?> |
PHP页面跳转三、JavaScript(常用、推荐)
例如,此代码可以放在程序中的任何合法位置。
代码如下 | 复制代码 |
$url = "http://www.111cn.net"; |
附一些js跳转方法
JavaScript 跳转
方法一:
代码如下 | 复制代码 |
方法二:
代码如下 | 复制代码 |
ASP 跳转
代码如下 | 复制代码 |
response.redirect "http://www.111cn.net" |

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

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

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

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

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools