Refreshing a web page can be essential for various scenarios, such as displaying real-time updates or triggering automated tasks. PHP provides a straightforward solution to refresh a page.
PHP provides the header() function, which allows you to send specific headers to the HTTP response. One of these headers is the Refresh header, which controls how a page is refreshed.
To refresh the current page periodically, use the following code:
header("Refresh:0");
This header refreshes the page immediately.
If you need to redirect users to another page after a specific time interval, you can use the following syntax:
header("Refresh:0; url=page2.php");
This header refreshes the page immediately and redirects users to page2.php.
The above is the detailed content of How Can I Refresh a PHP Page and Redirect Using the `header()` Function?. For more information, please follow other related articles on the PHP Chinese website!