使用 PHP 刷新页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12383371/
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-25 03:27:55  来源:igfitidea点击:

Refresh a page using PHP

phprefresh

提问by Aan

How can I refresh a page using PHP periodically? If I can not do it by PHP, what is the best recommended scenario?

如何使用 PHP 定期刷新页面?如果我不能通过 PHP 做到这一点,最好的推荐方案是什么?

回答by

You can do it with PHP:

你可以用 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");

回答by AboQutiesh

In PHPyou can use:

PHP 中,您可以使用:

$page = $_SERVER['PHP_SELF'];
$sec = "10";
header("Refresh: $sec; url=$page");

Or just use JavaScript's window.location.reload().

或者只是使用 JavaScript 的window.location.reload().

回答by 131

You sure can refresh a page periodically using PHP:

您肯定可以使用 PHP 定期刷新页面:

<?php
    header("refresh: 3;");
?>

This will refresh the page every three seconds.

这将每三秒刷新一次页面。

回答by Kamlesh

That is simply possible with header()in PHP:

在 PHP 中使用header()就可以做到这一点:

header('Refresh: 1; url=index.php');

回答by Thanos

I've found two ways to refresh PHP content:

我找到了两种刷新 PHP 内容的方法:

1. Using the HTML metatag:

1. 使用 HTMLmeta标签:

echo("<meta http-equiv='refresh' content='1'>"); //Refresh by HTTP 'meta'

2. Using PHP refresh rate:

2.使用PHP刷新率:

$delay = 0; // Where 0 is an example of a time delay. You can use 5 for 5 seconds, for example!
header("Refresh: $delay;"); 

回答by Mathlight

Besides all the PHP ways to refresh a page, the page will also be refreshed with the following HTML meta tag:

除了刷新页面的所有 PHP 方式外,页面还将使用以下 HTML 元标记进行刷新:

<meta http-equiv="refresh" content="5">

See Meta refresh- "automatically refresh the current web page or frame after a given time interval"

元刷新- “在给定的时间间隔后自动刷新当前网页或框架”

You can set the time within the contentvalue.

您可以在content值内设置时间。

回答by Patriks

PHPis server-side language, so you can not refresh the page with PHP, but JavaScript is the best option to refresh the page:

PHP是服务器端语言,所以你不能用 PHP 刷新页面,但 JavaScript 是刷新页面的最佳选择:

location.reload();

The visit Location reload() method.

访问Location reload() 方法

回答by Ben Guest

header('Location: .');seems to refresh the page in Chrome, Firefox, Edge, and Internet Explorer 11.

header('Location: .');似乎在 Chrome、Firefox、Edge 和 Internet Explorer 11 中刷新页面。

回答by Siddharth Shukla

Adding this meta tag in PHP might help:

在 PHP 中添加这个元标记可能会有所帮助:

echo '<META HTTP-EQUIV="Refresh" Content="0; URL=' . $location . '">';

回答by Prakash Patil

Echo the metatag like this:

meta像这样回显标签:

URL is the one where the page should be redirected to after the refresh.

URL 是页面应该在刷新后重定向到的位置。

echo "<meta http-equiv=\"refresh\" content=\"0;URL=upload.php\">";