Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP refresh window? equivalent to F5 page reload?

Is there anything in PHP that is the equivalent of manually pressing the F5 page reload button? My php script is in a frame and isn't the parent script but it needs to refresh the entire page and not just it's frame.

like image 889
user840930 Avatar asked Dec 02 '11 19:12

user840930


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 I trigger a refresh page?

reload() method reloads the current web page. The method gives the exact same result as pressing the RELOAD button in your browser. The JavaScript reload page method loads the page from the cache by default. If the forceGet property is set to true, the page is reloaded from the server.

How do you create a refresh page in HTML?

Most people know it can be done by hand by holding the shift key and clicking the “Refresh” (on IE) or “Reload” (on Navigator) buttons.


2 Answers

Actually it is possible:

Header('Location: '.$_SERVER['PHP_SELF']);
Exit(); //optional

And it will reload the same page.

like image 193
NewProger Avatar answered Oct 16 '22 19:10

NewProger


If you have any text before a

header('Location: http://www.example.com/youformhere.php');

you'll have issues, because that must be sent before any other text is sent to the page.

Try using this code instead

<?php 
$page = $_SERVER['PHP_SELF'];
echo '<meta http-equiv="Refresh" content="0;' . $page . '">';
?>

Just remember, this code will create and infinite loop, so you'll probably need to make some conditional changes to it.

like image 7
vr_driver Avatar answered Oct 16 '22 20:10

vr_driver