search
Homephp教程php手册用PHP实现页面跳转的三种方法

用PHP实现页面跳转的三种方法

Jun 06, 2016 pm 08:31 PM
phpPage jump

本篇文章是对PHP跳转页面的几种实现方法进行了详细的分析介绍,需要的朋友参考下

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代码还会被执行。例如,将浏览器重定向到lamp兄弟连官方论坛

代码如下:

<  ?php 
//重定向浏览器 
header("Location:  lampbrother.net"); 
//确保重定向后,后续代码不会被执行 
exit;
?>

PHP页面跳转二、Meta标签

Meta标签是HTML中负责提供文档元信息的标签,在PHP程序中使用该标签,也可以实现页面跳转。 若定义http-equiv为refresh,则打开该页面时将根据content规定的值在一定时间内跳转到相应页面。
若设置content="秒数;url=网址",则定义了经过多长时间后页面跳转到指定的网址。例如,使用meta标签实现疫苗后页面自动跳转到LAMP兄弟连官方论坛。

代码如下:

<   meta   http-equiv = "refresh"  
content = "1;url=http:// bbs.lampbrother.net" >

例如,虚拟主机,以下程序meta.php实现在该页面中停留一秒后页面自动跳转到bbs.lampbrother.net。  

代码如下:

<   html >    
<   head >    
<   meta   http-equiv = "refresh"   content ="1;  
url = <  ?php echo $url;  ?> " >    
<  /head >    
<   body >    
页面只停留一秒……   
<  /body >  
<  /html >

PHP页面跳转三、JavaScript
例如,此代码可以放在程序中的任何合法位置。

 代码如下:

<  ?php  
$ url  =  "http://bbs.lampbrother.net" ;  
echo " <   script   language = &#39;javascript&#39;  
type = &#39;text/javascript&#39; > ";  
echo " window.location.href = &#39;$url&#39; ";  
echo " <  /script > ";  
?>

以上就是我们向大家介绍的三种PHP页面跳转实现方法。

【相关教程推荐】

1. php编程从入门到精通全套视频教程
2. php从入门到精通 
3. bootstrap教程

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

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software