"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to Automatically Redirect a Web Page in PHP After a Specified Time?

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

Published on 2024-11-07
Browse:779

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:

header( "refresh:5;url=wherever.php" );

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.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3