简单:
只是有一些登录概念,或持久性cookie(登录更可靠,因为他们可以清除cookie).然后在您的数据库中有一个"上次登录"字段.如果上次登录的字段与昨天的日期匹配,则递增您的连续访问次数,否则重置它.
编辑:这可能是显而易见的,但请确保在今天检查后更新"上次登录"字段,否则每次加载页面时都会增加计数!
编辑:一个快速示例可能看起来像这样(伪代码):
// first you need to set $last seen from the DB..
// first you need to set consecutive from the DB too..
// once you have, you can do something like this.
if(strtotime('-1 day', date('Y-m-d')) == $last_seen) {
$consecutive = $consecutive + 1;
mysql_query(sprintf('UPDATE user SET last_seen=NOW(),consecutive=%d WHERE id=%d', $consecutive + 1, $id));
} else if(date('Y-m-d') == $last_seen) {
// ok, they logged in today again, do nothing.
} else {
$consecutive = 0; // only really needed if you plan on displaying it to the user
// later in this script
mysql_query(sprintf('UPDATE user SET last_seen=NOW(),consecutive=0 WHERE id=%d',$id));
}
Run Code Online (Sandbox Code Playgroud)