[英]Increment Counter after page auto refresh in PHP
I am very new to front end development so I am sorry if this is stupid. 我对前端开发非常陌生,所以对不起,我感到抱歉。 I am writing a webpage to display some info and I have the page auto refresh however, I would like to keep a counter static (ie not default to 0 after every refresh. What I have so far is 我正在写一个网页以显示一些信息,并且页面自动刷新,但是,我想保持一个计数器不变(即每次刷新后不默认为0。到目前为止,我有
<html>
<head>
<title>PAGE</title>
<link rel=StyleSheet href=css/mycss.css type="text/css">
<meta http-equiv="refresh" content="20">
</head>
<?php
session_start();
$_SESSION['count'] = 0;
echo "<body>"
$output = "";
$output .= "<div class=\"page_title .sb-con\">DASHBOARD</div>
if(isset($_SESSION['count']) )
{
echo "{$_SESSION['count']}\n";
$_SESSION['count'] = $_SESSION['count'] + 1;
}else{
$_SESSION['count'] = 0;
}
echo $output;
echo "</body>";
echo "</html>";
?>
thanks in advance! 提前致谢!
If you need to get this per user, then you can use PHP sessions : 如果您需要按用户获得此权限,则可以使用PHP 会话 :
The trick is to start a session, and then use $_SESSION
global array to store your informations. 诀窍是开始一个会话,然后使用$_SESSION
全局数组存储您的信息。 You can see simple examples of what you need here 您可以在这里看到所需的简单示例
But if you need to store this information globally, for all users, then you will have to use a database. 但是,如果您需要针对所有用户全局存储此信息,则必须使用数据库。 You can have a look at this tutorial . 您可以看一下本教程 。 You will find everything you need to understand and begin with MySQL. 您将找到需要了解的所有内容,并从MySQL开始。
Your code is ok but: 您的代码还可以,但是:
1. session_start();
1. session_start();
you place it first and after ...<html><title>PAGE</title>
您将其放在...<html><title>PAGE</title>
,然后...<html><title>PAGE</title>
2.you dont need: $_SESSION['count'] = 0
; 2.您不需要: $_SESSION['count'] = 0
; after session_start();
在session_start();
Your code increment:$_SESSION['count']
, it works. 您的代码increment:$_SESSION['count']
,它可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.