每日签到的功能,供大家参考,具体内容如下
首次签到获得1个积分,第二次签到获得2个积分,第三次签到获得3个积分,以此类推但是签到必须每天连续积分才可以递增,如果有中断再次签到时获得积分仍然从1开始递增;
user: id,username,count,point,sign_time
sign.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>sign</title> </head> <body> <center> <input type="text"> <button>签到</button><span></span> <div> <table></table> </div> </center> </body> </html> <script src="https://www.jb51.net/jquery.1.12.min.js"></script> <script> $(function(){ $('button').click(function(){ var username=$(':text').val(); $.ajax({ type:'post', url:'admin.php', data:{username:username}, dataType:'json', success:function(res){ if(res.success==1){ $('#span').html('签到成功'); var str='<tr><td>用户名</td><td>连续签到天数</td><td>总积分</td></tr>'; str+='<tr><td>'+res.msg.username+'</td><td>'+res.msg.count+'</td><td>'+res.msg.point+'</td></tr>'; $('#box').html(str); } } }) }); }) </script>
admin.php
<?php header('content-type:text/html;charset=utf-8'); $pdo=new PDO('mysql:host=localhost;dbname=databasename;','root','root'); $pdo->exec('set names utf8'); $username=$_POST['username']; $sqlQuery="select * from user where username='$username'"; $row=$pdo->query($sqlQuery)->fetch(PDO::FETCH_ASSOC); if($row){ $sign_time=$row['sign_time']; $sign_time=strtotime($sign_time); $int=date('Y-m-d'); $int=strtotime($int);//5 $ints=$int+86400; //6 $int_s=$int-86400; //4 //当天已签到 if($int<$sign_time&&$sign_time<$ints){ // echo '您已签到'; } //昨天未签到,积分,天数在签到修改为1 if($sign_time<$int_s){ $count=1; $point=1; $sign_time=date('Y-m-d H:s:i'); $sqlRow="update user set count='$count',point='$point',sign_time='$sign_time' where username='$username'"; $res=$pdo->exec($sqlRow); // echo '签到成功修改为1'; } //请签到 if($int_s<$sign_time&&$sign_time<$int){ $count=$row['count']+1; $point=$row['point']+1; $sign_time=date('Y-m-d H:s:i'); $sqlupdate="update user set count='$count',point='$point',sign_time='$sign_time' where username='$username'"; $res=$pdo->exec($sqlupdate); // echo '签到成功+1'; } }else{ $count=1; $point=1; $sign_time=date('Y-m-d H:s:i'); $sqlAdd="insert into user values (null,'$username','$count','$point','$sign_time')"; $res=$pdo->exec($sqlAdd); // echo '恭喜你签到成功----1'; } //////////////////////响应 $sqlEnd="select * from user where username='$username'"; $info=$pdo->query($sqlEnd)->fetch(PDO::FETCH_ASSOC); echo json_encode(array('success'=>1,'msg'=>$info));die; ?>