php PHP刷新窗口?相当于 F5 页面重新加载?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8361253/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 04:31:02  来源:igfitidea点击:

PHP refresh window? equivalent to F5 page reload?

phprefreshreload

提问by user840930

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.

PHP 中有什么东西相当于手动按下 F5 页面重新加载按钮?我的 php 脚本在一个框架中,而不是父脚本,但它需要刷新整个页面,而不仅仅是它的框架。

采纳答案by gustavotkg

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

使用 PHP,您可以处理服务器端的东西。你可以做的是在你的 iframe 中打印:

parent.window.location.reload();

回答by NewProger

Actually it is possible:

其实是可以的:

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

And it will reload the same page.

它会重新加载同一个页面。

回答by vr_driver

If you have any text before a

如果你在 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.

请记住,此代码将创建无限循环,因此您可能需要对其进行一些有条件的更改。

回答by Madara's Ghost

PHP cannot force the client to do anything. It cannot refresh the page, let alone refresh the parent of a frame.

PHP 不能强迫客户端做任何事情。它无法刷新页面,更不用说刷新框架的父级了。

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 编写 JavaScript,但这不是 PHP 所做的,它实际上是 JavaScript,如果禁用 JavaScript,它将失败。

<?php
    echo '<script>parent.window.location.reload(true);</script>';
?>

回答by Mehrdad

with php you can use two redirections. It works same as refresh in some issues.

使用 php,您可以使用两个重定向。它在某些问题中与刷新相同。

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.

您可以使用页面 redirect.php 并通过 GET 方法将您的最后一个 url 发布到它(例如)。然后在redirect.php中,您可以将标头更改为通过GET方法发送给它的位置。

like this: your page:

像这样:您的页面:

<?php
header("location:redirec.php?ref=".$your_url);
?>

redirect.php:

重定向.php:

<?php
$ref_url=$_GET["ref"];
header("location:redirec.php?ref=".$ref_url);
?>

that worked for me good.

这对我很有用。

回答by Vineesh Kalarickal

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

回答by user20200

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

像这样:刷新选择

回答by jValdron

Use JavaScript for this. You can do:

为此使用 JavaScript。你可以做:

echo '
<script type="text/javascript">
   parent.window.location.reload(true);
</script>
';

In PHP and it will refresh the parent's frame page.

在 PHP 中,它将刷新父级的框架页面。

回答by optimusprime619

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

回答by user3787931

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