PHP - auto refreshing page
To refresh a page in PHP, you can use the header
function to send the HTTP "Refresh" header to the client's browser. This will cause the browser to refresh the page after a specified number of seconds.
Here is an example of how you can use the header
function to refresh a page after 5 seconds:
<?php
header("Refresh: 5");
?>
Watch a video course
Learn object oriented PHP
You can also specify the URL to refresh the page to by adding it as the second argument to the header
function:
<?php
header("Refresh: 5; url=http://example.com/");
?>
Keep in mind that the header
function must be called before any other output is sent to the browser. If you have already sent output to the browser, you will need to use a meta refresh tag instead. Here is an example of how you can use a meta refresh tag to refresh a page after 5 seconds:
<meta http-equiv="refresh" content="5">