Home Backend Development PHP Tutorial PHP重定向的3种方式

PHP重定向的3种方式

May 17, 2016 am 09:06 AM
php redirect Way


本文介绍了“PHP重定向的3种方式”,需要的朋友可以参考一下.

微信截图_20181113143100.png

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   
//重定向浏览器   
header("Location: http://blog.csdn.net/abandonship");   
//确保重定向后,后续代码不会被执行   
exit;  
?>
Copy after login

PHP页面跳转二、Meta标签

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

< meta http-equiv="refresh" content="1;url=http://blog.csdn.net/abandonship">

例,以下程序meta.php实现在该页面中停留一秒后页面自动跳转。

<?php     
$url = "http://blog.csdn.net/abandonship";   
?>   
<html>     
<head>     
<meta http-equiv="refresh" content="1;url=<?php echo $url; ?>">     
</head>     
<body>   
It&#39;s transit station.  
</body>  
</html>
Copy after login

PHP页面跳转三、JavaScript

<?php    
$url = "http://blog.csdn.net/abandonship";  
echo "<script type=&#39;text/javascript&#39;>";  
echo "window.location.href=&#39;$url&#39;";  
echo "</script>";   
?>
Copy after login

以上就是对PHP重定向的3种方式的全部介绍,如果您想了解更多有关php编程入门,请关注PHP中文网。


Statement of this Website
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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What are the methods of time processing in Go language? What are the methods of time processing in Go language? Jun 10, 2023 pm 09:42 PM

As a modern programming language, Go language plays an important role in development. The Go language provides some built-in time functions and structures to make time processing more convenient. In this article, we will introduce some commonly used time processing methods in the Go language. time.Now() We can use the time.Now() function to get the current time: now:=time.Now()fmt.Println(now) output: 2019-06-131

How to remove unwanted URLs from Chrome's address bar? How to remove unwanted URLs from Chrome's address bar? Mar 08, 2024 am 09:19 AM

Chrome will automatically record the URLs that have been entered in the address bar, and will automatically "associate query content" in the future. But many times we don't need some URLs, how to delete them? The editor often encounters this problem. Addresses that have been entered before will be blocked in front of commonly used addresses, resulting in the need to select several times to enter the desired website. I have looked for how to delete it at least three times because... I forget it every time. In the address bar shortcuts of Chrome's official help Chrome keyboard shortcuts, the delete shortcut key is clarified: ▍Windows deletes the address bar association content. Press the down arrow key to highlight the corresponding content, and then press the Shift+Delete key ▍macOS deletes the address Bar association content click down

How to use shortcuts on iPhone How to use shortcuts on iPhone Nov 29, 2023 am 09:06 AM

These shortcuts can be used for a variety of different things on iPhone&gt; In today's dynamic and fast-moving world, where the pursuit of efficiency and convenience takes center stage, the Shortcuts app on iPhone stands out as a very Powerful tool. It's designed to simplify and speed up daily tasks, significantly increasing productivity. This app is incredibly adaptable, enabling users to automate mundane, repetitive actions that consume precious time. Additionally, it provides tools to tailor personalized commands to individual needs and preferences. What's particularly noteworthy about the Shortcuts app is its integration with Apple's smart assistant, Siri. This feature allows the use of intuitive speech

How to delete win10 input method How to delete win10 input method Detailed introduction How to delete win10 input method How to delete win10 input method Detailed introduction Jul 07, 2023 pm 05:33 PM

The win10 input method has made great progress compared with previous system versions, and has many very useful functions. It is also very smooth to use overall and has the function of memory typing. However, some users already have their own input methods that are good to use. Now, if you want to delete the built-in win10 input method, how do you delete the win10 input method? Today I will tell you the details about how to delete the win10 input method. How to delete the input method in win10 1. Press [Win+i] to open the settings interface, and click on the "Time and Language" option. 2. Click "Region and Language" and click the "Options" button under "Chinese" on the right. 3. Click the "Microsoft Pinyin Alphabet" option and the "Delete" button will appear.

How to set restore point in win7 How to set restore point in win7 Jul 20, 2023 am 10:33 AM

The win7 system is Microsoft's traditional operating system and has many practical functions, such as the function of win7 system restore points. By setting a restore point in win7, you can restore the system to the restore point in win7 to achieve the purpose of system repair. How to set restore point in win? The following editor will teach you how to set a restore point in win7. How to set a restore point in win7 1. Find the desktop shortcut, right-click and select Properties. 2. After entering the property settings, select Advanced System Configuration. 3. Select the system maintenance option in the pop-up system properties box. 4. Click to create a restore point now for the controller with system protection turned on. 5. Add a description of the restore point, then click Create, wait patiently for a while, the restore point is successfully established, and then click Close. You can restore the system next time.

How to upgrade win7 system from xp system How to upgrade win7 system from xp system Jul 13, 2023 am 08:53 AM

The xp system can be said to be a computer system that Microsoft released a long time ago. Currently, very few people are using it. The key is to use it on old computers. Many netizens want to upgrade the xp system to win7, but they don’t know how to upgrade the xp system to win7. .The actual operation steps will be demonstrated below. 1. Download and install the three-step software for beginners and open it. Select the win7 system and click to reinstall immediately. 2. Wait for the tool to automatically download the win7 system. 3. Reinstall the Windows system online immediately after downloading, please follow the prompts. 4. After the installation is completed, you can choose to restart immediately. 5. Enter the run menu bar and select the second item XiaoBaiPE-MSDNOnlineIns

What are the methods of type conversion in Go language? What are the methods of type conversion in Go language? Jun 11, 2023 am 09:05 AM

As the Go language becomes increasingly popular in the Internet industry, more and more developers are beginning to get involved in this language. In the Go language, type conversion is also one of the common programming operations. This article will introduce some common type conversion methods. Type assertion Type assertion is an operation that converts an interface type to another type. In Go language, type assertion can be made using the following syntax: value,ok:=interface{}.(type) where value represents the converted value, o

What are the signal processing methods in Go language? What are the signal processing methods in Go language? Jun 11, 2023 pm 12:28 PM

What are the signal processing methods in Go language? Go language is an efficient, concise programming language with native concurrency capabilities. It is widely used in network programming, distributed systems, cloud computing and other fields. In Go language, inter-process communication is implemented through pipes and signals. This article will introduce the use of signals and their processing methods in the Go language. Signals Overview A signal is a mechanism used by the operating system to send asynchronous events to processes. In Unix/Linux operating systems, signals are often used to notify processes of certain

See all articles