How to use header() in php to jump to the page?

青灯夜游
Release: 2023-03-04 22:14:01
Original
5085 people have browsed it

php method to use header() to jump to the page: 1. Use "header('Location:url page address');" to jump to the page immediately; 2. Use "header('Refresh:time,Url =url page address');" Jump to the page at the specified time (seconds).

How to use header() in php to jump to the page?

Recommended: "PHP Video Tutorial"

php uses header() to jump Page methods

#1. Jump to the page immediately

header('Location:url页面地址');  //Location和":"之间无空格
Copy after login

Example:

header('Location:other.php');
//file_put_contents('bee.txt','execute');
die;
Copy after login

When executing the header, It does not end immediately, but will complete the execution of the page; there cannot be any output in front of the header. If the output buffer is turned on, no error will be prompted.

php.ini->output_buffering = 4096|OFF
Copy after login

2. Jump to the page regularly

header('Refresh:time,Url=url页面地址');
Copy after login

Example:

header('Refresh:3,Url=//m.sbmmt.com/');   //3s后跳转
echo '3s 后跳转';
//由于只是普通页面展示,提示的样式容易定制
die;
Copy after login

Description:

header() function sends the original HTTP header to the client.

It is important to realize that the header() function must be called before any actual output is sent

Related learning recommendations: PHP Programming from Beginner to Mastery

The above is the detailed content of How to use header() in php to jump to the page?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!