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>
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!