Home>Article>Backend Development> How to use header() in php to jump to the page?

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

青灯夜游
青灯夜游 Original
2020-08-21 11:47:24 5103browse

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和":"之间无空格

Example:

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

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

2. Jump to the page regularly

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

Example:

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

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!

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