A small function for continuous check-in on the website!
When you are doing website development, have you ever encountered members who sign in continuously to get points? For example, I have a rule to add points for continuous sign-ins. So when we implement this function, we face There are a few points to note: (1) The number of consecutive sign-ins must be accumulated, which involves the judgment between two timestamps. (2) Whether the sign-in is this month, of course, in this case, the judgment between the two timestamps is also That's solved, but you should also pay attention to this point (3) If it is consecutive, it will be added by 1, otherwise it will be cleared to 0. Also, if you have not signed in before, a sign-in record will be generated! Below I will post a piece of code to implement the sign-in. Everyone is welcome to learn and progress together!
Table structure:
/**How to implement continuous check-ins*/
public function signList(){
/**First check if there is this user*/
$m_id = $_GET['m_id'];
$sign = D('Sign')->where(array("m_id"=>$m_id))->limit(0)->find();
/**If there is, judge the time difference and then process the number of check-ins.*/
if($sign){
/**Yesterday's timestamp time range*/
$t = time();
$last_start_time = mktime(0,0,0,date("m",$t),date("d",$t)-1,date("Y",$t));
$last_end_time = mktime(23,59,59,date("m",$t),date("d",$t)-1,date("Y",$t));
/**Today's timestamp time range*/
// $now_start_time = mktime(0,0,0,date("m",$t),date("d",$t),date("Y",$t));
// $now_end_time = mktime(23,59,59,date("m",$t),date("d",$t),date("Y",$t));
/**Determine whether the last check-in time is within yesterday's time range*/
if($last_start_time
$da['time'] = time();
$da['count'] = $sign['count']+1;
/**You can also add some operations here to determine how many consecutive days you have signed in and then add points, etc.*/
D('Sign')->where(array("m_id"=>$m_id))->save($da);
}else{
/**Return to checked-in operations*/
$da['time'] = time();
$da['count'] = 0;
D('Sign')->where(array("m_id"=>$m_id))->save($da);
}
}else{
$data['m_id'] = $m_id;
$data['time'] = time();
$data['sign'] = 1;
$res = D("Sign")->add($data);
if($res){
/**Return if successful, or handle some procedures, such as adding points*/
}
}
}

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Atom editor mac version download
The most popular open source editor

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
