Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refresh a page using PHP

Tags:

php

refresh

People also ask

Can I refresh a page from PHP?

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();

How do you refresh a page?

F5 or Ctrl+R or clicking the Reload button on the location/address bar reloads the current tab.

How do you refresh a page in HTML?

The reload() method reloads the current document. The reload() method does the same as the reload button in your browser.

How will you redirect a page using PHP?

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');