PHP is server-side language, so you can not refresh the page with PHP, but JavaScript is the best option to refresh the page: location. reload();
F5 or Ctrl+R or clicking the Reload button on the location/address bar reloads the current tab.
The reload() method reloads the current document. The reload() method does the same as the reload button in your browser.
How Redirection Works in PHP. In PHP, when you want to redirect a user from one page to another page, you need to use the header() function. The header function allows you to send a raw HTTP location header, which performs the actual redirection as we discussed in the previous section.
You can do it with PHP:
header("Refresh:0");
It refreshes your current page, and if you need to redirect it to another page, use following:
header("Refresh:0; url=page2.php");
In PHP you can use:
$page = $_SERVER['PHP_SELF'];
$sec = "10";
header("Refresh: $sec; url=$page");
Or just use JavaScript's window.location.reload()
.
You sure can refresh a page periodically using PHP:
<?php
header("refresh: 3;");
?>
This will refresh the page every three seconds.
That is simply possible with header() in PHP:
header('Refresh: 1; url=index.php');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With