PHP refresh window? equivalent to F5 page reload?

给你一囗甜甜゛ 提交于 2019-11-29 18:31:01

问题


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.


回答1:


With PHP you just can handle server-side stuff. What you can do is print this in your iframe:

parent.window.location.reload();



回答2:


Actually it is possible:

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

And it will reload the same page.




回答3:


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.




回答4:


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



回答5:


<?php 
echo "<script>window.opener.location.reload();</script>";
echo "<script>window.close();</script>";
?>



回答6:


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.




回答7:


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.




回答8:


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"> 



回答9:


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




回答10:


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{}
?>


来源:https://stackoverflow.com/questions/8361253/php-refresh-window-equivalent-to-f5-page-reload

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!