Home >Backend Development >PHP Tutorial >How Can I Refresh a PHP Page and Redirect Using the `header()` Function?

How Can I Refresh a PHP Page and Redirect Using the `header()` Function?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-25 08:11:47193browse

How Can I Refresh a PHP Page and Redirect Using the `header()` Function?

PHP Page Refresh

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 Refresh Function

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.

Redirecting to Another Page

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!

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