This article mainly introduces to you the detailed explanation of the three methods of PHP to implement page redirection.
So what is page redirection?
In the process of website development, when we encounter web page migration or website adjustment, we need to make a redirection to prevent traffic loss. Page redirection is to redirect various network requests to other locations through various methods.
Below we will introduce to you the specific method of implementing page redirection through simple code examples.
Method 1: header redirection
<?php $url = "http://php.cn"; if (isset($url)) { header("Location:$url"); } else { echo "没有跳转的地址!"; }
Here we define a $url variable, which represents the url address to be redirected to. Then use if to determine whether the redirect link exists. If it exists, jump to the new address "http://php.cn". If not, output "No jump address!".
If no jump link is defined, the return value is as follows:
If a new url is defined, it is normal The jump is as follows:
Note : The header() function sends the original HTTP header to the client. The parameter is the new url address.
Method 2: js script redirection
<?php $url = "http://php.cn"; if (isset($url)) { echo "<SCRIPT language= 'JavaScript'>location.href='$url'</SCRIPT>"; } else { echo "没有跳转的地址!"; }
Also first determine whether the link exists, and then here we mainly use location.href in js, that is It means jump.
Method three: html tag redirection
<?php $url = "http://php.cn"; if (!isset($url)) { exit("没有跳转的地址!"); } ?> <HTML> <head> <meta HTTP-EQUIV="REFRESH" CONTENT="3; URL='<?php echo $url; ?>' "> </head> <body> </body>
Similarly, we first determine whether there is a jump link, and then mainly use
In the tag, REFRESH means defining a refresh, 3 is the refresh time, the unit is seconds, and the parameter in the URL is the refreshed file, that is, the new jump link address.
This article is a detailed introduction to the three methods of implementing page redirection in PHP. I hope it will be helpful to friends in need!
If you want to learn more about PHP, you can follow the PHP Chinese website PHP Video Tutorial. Everyone is welcome to learn and refer to it.
The above is the detailed content of How to implement page redirection in PHP? (Pictures + Videos). For more information, please follow other related articles on the PHP Chinese website!

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

Zend Studio 13.0.1
Powerful PHP integrated development environment

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

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

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

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.