search
Homephp教程php手册PHP重定向的三种方式

PHP重定向的三种方式

Jun 13, 2016 am 10:28 AM
php

Web系统中,从一个网页跳转到另一个网页,是LAMP项目中最常用的技术之一。页面跳转可能是由于用户单击链接、按钮等引发的,也可能是系统自动产生的。 此处介绍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: http://bbs.lampbrother.net"); //确保重定向后,后续代码不会被执行 exit;?>
< meta http-equiv="refresh" content="1;url=http://bbs.lampbrother.net">
< ?php   $url = "http://bbs.lampbrother.net"; ?> < html>   < head>   < meta http-equiv="refresh" content="1;  url=< ?php echo $url; ?>">   < /head>   < body>   页面只停留一秒……   < /body> < /html>
< ?php  $url = "http://bbs.lampbrother.net";  echo "< script language=&#39;javascript&#39; type=&#39;text/javascript&#39;>";  echo "window.location.href='$url'";  echo "< /script>";  ?>

更多相关教程请访问 php编程从入门到精通全套视频教程

Statement
This article is reproduced at:CSDN博客. If there is any infringement, please contact admin@php.cn delete

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

MantisBT

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.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

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

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

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.