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

Atom editor mac version download
The most popular open source editor

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver Mac version
Visual web development tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

Dreamweaver CS6
Visual web development tools
