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.
10 Answers
Actually it is possible:
Header('Location: '.$_SERVER['PHP_SELF']);
Exit(); //optional
And it will reload the same page.
-
This one should be marked as approved because it does exactly what's intended in php (no javascript or insertion into HTML). Nov 17, 2013 at 18:11
-
@Ryuji This does NOT solve the original question. How would this cause the parent document to reload? Nov 21, 2013 at 21:53
-
1@MikeBrant because that is exactly what it does. It orders php to reload the same page. Nov 30, 2013 at 15:10
-
@NewProger You do realize that this would result in an infinite redirect? Also you realize that the original question was about reloading a parent window from a child window, which this does absolutely nothing to solve. Just because the OP asked for a PHP solution, doesn't mean there is one. Dec 2, 2013 at 17:05
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.
With PHP you just can handle server-side stuff. What you can do is print this in your iframe:
parent.window.location.reload();
-
-
1. . . a further question. I did: echo "<body onload=\"parent.window.location.reload()\">"; which reloads the entire page which is just I need, but the frame in which the executing php script was in, is not updating. And I can't seem to call another parent.window.location.reload or even a onload=\"window.location='$page'\" what can I do? Dec 2, 2011 at 20:03
-
not sure I got it, but have you checked your frame src? Check if parent.window is loading it correctly... Dec 2, 2011 at 20:10
-
I checked the frame source, and it's correct. But the frame is not loading correctly on parent.window.location.reload(). Not sure why. How can I check that parent.window is loading it correctly? Dec 2, 2011 at 20:23
-
1
parent.window.location.reload()
will reload the current page whatever it is. You have to check yourparent.window.location.href
source code =) Dec 2, 2011 at 20:26
PHP cannot force the client to do anything. It cannot refresh the page, let alone refresh the parent of a frame.
EDIT: You can of course, make PHP write JavaScript, but this is not PHP doing, it's actually JavaScript, and it will fail if JavaScript is disabled.
<?php
echo '<script>parent.window.location.reload(true);</script>';
?>
<?php
echo "<script>window.opener.location.reload();</script>";
echo "<script>window.close();</script>";
?>
with php you can use two redirections. It works same as refresh in some issues.
you can use a page redirect.php and post your last url to it by GET method (for example). then in redirect.php you can change header to location you`ve sent to it by GET method.
like this: your page:
<?php
header("location:redirec.php?ref=".$your_url);
?>
redirect.php:
<?php
$ref_url=$_GET["ref"];
header("location:redirec.php?ref=".$ref_url);
?>
that worked for me good.
Use JavaScript for this. You can do:
echo '
<script type="text/javascript">
parent.window.location.reload(true);
</script>
';
In PHP and it will refresh the parent's frame page.
guess you could echo the meta tag to do the refresh in regular intervals ... like
<meta http-equiv="refresh" content="600" url="your-url-here">
All you need to do to manually refresh a page is to provide a link pointing to the same page
Like this: Refresh the selection
Adding following in the page header works for me:
<?php
if($i_wanna_reload_the_full_page_on_top == "yes")
{
$reloadneeded = "1";
}
else
{
$reloadneeded = "0";
}
if($reloadneeded > 0)
{
?>
<script type="text/javascript">
top.window.location='indexframes.php';
</script>
<?php
}else{}
?>