Use header() function to refresh a web page in PHP. The HTTP functions are those functions which manipulate information sent to the client or browser by the Web server before any other output has been sent. The PHP header() function sends an HTTP header to a client or browser in raw form. Before HTML, XML, JSON or other output has been sent to a browser or client, a raw data is sent with the request (especially HTTP Request) made by the server as header information. HTTP header provides required information about the object sent in the message body more precisely about the request and response.
void header( $header, $replace = TRUE, $http_response_code ) Or header(string, replace, http_response_code)
- $header: It holds the header string. There are two types of header calls. The first header starts with string “HTTP/”, which is used to figure out the HTTP status code to send. The second case of header is the “Location:”. It is mandatory parameter.
- $replace: It is optional parameter. It denotes the header should replace previous or add a second header. The default value is True (will replace). If $replace value is False then it force multiple headers of the same type.
- $http_response_code: It is an optional parameter. It forces the HTTP response code to the specified value (PHP 4.3 and higher).
Note: This function prevents more than one header to be sent at once. This is a protection against header injection attacks after PHP 4.4 release.
Below example illustrates the use of header() to refresh current page in PHP:
Example: This example uses header() function to refresh a web page in every 3 seconds.
Example 2: This example uses header() function to redirect web page into another page.
- How to refresh a page using jQuery?
- How to refresh parent page on closing a popup ?
- How to pass form variables from one page to other page in PHP ?
- How to refresh a file in Node.js ?
- What’s the best way to reload / refresh an iframe?
- Pull to Refresh with ListView in Android with Example
- How to display search result of another page on same page using ajax in JSP?
- How to show Page Loading div until the page has finished loading?
- How to redirect a page to another page in HTML ?
- How to create admin login page using PHP ?
- PHP Program to count Page Views
- How to add API function to a simple PHP Page ?
- How to minify HTML code of PHP page ?
- How to connect the Database with PHP DOM page ?
- How to add a PHP page to WordPress?
- How to hide an element when printing a web page using CSS?
- HTML | Responsive full page image using CSS
- Download web page using Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.