PHP - 自动刷新页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11497611/
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
PHP - auto refreshing page
提问by Fou
I am using following code for a refreshing page, it is not reloading on completion. The following code is not working sometime.
我正在使用以下代码刷新页面,完成后不会重新加载。以下代码有时不起作用。
$page = $_SERVER['PHP_SELF'];
$sec = "10";
header("Refresh: $sec; url=$page");
echo "Watch the page reload itself in 10 second!";
回答by nickb
Use a <meta>redirect instead of a header redirect, like so:
使用<meta>重定向而不是标头重定向,如下所示:
<?php
$page = $_SERVER['PHP_SELF'];
$sec = "10";
?>
<html>
<head>
<meta http-equiv="refresh" content="<?php echo $sec?>;URL='<?php echo $page?>'">
</head>
<body>
<?php
echo "Watch the page reload itself in 10 second!";
?>
</body>
</html>
回答by Ram Aquino
you can use
您可以使用
<meta http-equiv="refresh" content="10" >
just add it after the head tags
只需将其添加到 head 标签之后
where 10 is the time your page will refresh itself
其中 10 是您的页面将自行刷新的时间
回答by Junaid Akram
use this code ,it will automatically refresh in 5 seconds, you can change time in refresh
使用此代码,它会在 5 秒后自动刷新,您可以在刷新中更改时间
<?php
$url1=$_SERVER['REQUEST_URI'];
header("Refresh: 5; URL=$url1");
?>
<?php
$url1=$_SERVER['REQUEST_URI'];
header("Refresh: 5; URL=$url1");
?>
回答by Gideon Afoh
Try out this as well. Your page will refresh every 10sec
也试试这个。您的页面将每 10 秒刷新一次
<html>
<head>
<meta http-equiv="refresh" content="10; url="<?php echo $_SERVER['PHP_SELF']; ?>">
</head>
<body>
</body>
</html>
回答by Ali ?zy?ld?r?m
Maybe use this code,
也许使用此代码,
<meta http-equiv="refresh" content = "30" />
take it be easy
放轻松
回答by Fikri Yogi
Simple step like this,
像这样简单的步骤,
<!DOCTYPE html>
<html>
<head>
<title>Autorefresh Browser using jquery</title>
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript">
$(function() {
startRefresh();
});
function startRefresh() {
setTimeout(startRefresh,100);
$.get('text.html', function(data) {
$('#viewHere').html(data);
});
}
</script>
</head>
<body>
<div id="viewHere"></div>
</body>
</html>
This video for complete tutorial https://youtu.be/Q907KyXcFHc
此视频完整教程 https://youtu.be/Q907KyXcFHc
回答by russell newton
This works with Firefox Quantum 60+ and Chrome v72 (2019)
这适用于 Firefox Quantum 60+ 和 Chrome v72 (2019)
//set a header to instruct the browser to call the page every 30 sec
header("Refresh: 30;");
It does not seem to be NECESSARY to pass the page url as well as the refresh period in order to (re)call the same page. I haven't tried this with Safari/Opera or IE/Edge.
为了(重新)调用同一页面,似乎不需要传递页面 url 和刷新周期。我还没有在 Safari/Opera 或 IE/Edge 上试过这个。
回答by Sushant Samleti
<meta http-equiv="refresh" content="10" >
<meta http-equiv="refresh" content="10" >
This can work. Try it..!! :-)
这可以工作。尝试一下..!!:-)

