Refresh a page using PHP
You can refresh a page using PHP using the header
function. This function allows you to send a new HTTP header to the client browser. You can use it to redirect the user to a different page or to refresh the current page.
To refresh the current page, you can use the following code:
<?php
header("Refresh:0");
This will refresh the page after 0 seconds, which means it will refresh the page immediately. You can also specify a different time in seconds if you want to refresh the page after a certain amount of time.
For example, to refresh the page after 5 seconds, you can use the following code:
<?php
header("Refresh:5");
You can also use the header
function to redirect the user to a different page. For example, to redirect the user to the home page, you can use the following code:
<?php
header("Location: /index.php");
Keep in mind that the header
function must be called before any output is sent to the client browser. If you have already outputted something to the browser, you will need to use a JavaScript solution to refresh the page.