How to Automatically Redirect a Web Page in PHP After a Specified Time?

Mary-Kate Olsen
Release: 2024-10-29 08:32:30
Original
386 people have browsed it

How to Automatically Redirect a Web Page in PHP After a Specified Time?

Redirecting a Web Page Automatically after a Specified Time with PHP

PHP provides a convenient function for automatically redirecting a web page to a new location after a specified time interval. This functionality is commonly used to redirect users to a specific page after they log in or perform another action on a website.

The function used for this purpose is header(). The header() function allows you to control the HTTP headers that are sent to the browser. By setting an appropriate HTTP header, you can instruct the browser to redirect the user to a new URL after a given amount of time.

To redirect a web page after a specified time using PHP, simply call the header() function with the following arguments:

<code class="php">header( "refresh:5;url=wherever.php" );</code>
Copy after login

In the above example, the page will be redirected to wherever.php after 5 seconds. You can adjust the time value to suit your needs.

Important Note: It's crucial to call the header() function before any output is sent to the browser. This includes HTML tags, blank lines, or any other text. If output is sent before the header() function is called, the redirect will not work properly.

The above is the detailed content of How to Automatically Redirect a Web Page in PHP After a Specified Time?. For more information, please follow other related articles on the PHP Chinese website!

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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template