无为清净楼资源网 Design By www.qnjia.com

本文实例讲述了PHP连续签到功能实现方法。分享给大家供大家参考,具体如下:

require "./global.php";
  $act = isset($_GET['act']) "error";
  // d($act);
  switch($act){
    case "qiandao":
      $uid = intval($_POST['uid']);
      $res = $db -> get('qian_dao','*',array('uid'=>$uid));
      // last_query();
      $time = time();
      //判断今天是否签到
      $todayBegin=strtotime(date('Y-m-d')." 00:00:00"); 
      $todayEnd= strtotime(date('Y-m-d')." 23:59:59"); 
      $isexit = $db -> get('qian_dao','id',array('AND'=>array('uid'=>$uid,'qian_dao_time[>=]'=>$todayBegin,'qian_dao_time[<=]'=>$todayEnd)));
      // last_query();
      if($isexit){
        // echo "今天已签到!";
        Log::writeLog(print_r(array('state'=>'stop','msg'=>'今天已签到!'),true));
        echo json_encode(array('state'=>'stop','msg'=>'今天已签到!'));
        exit;
      }
      if($res){
        //存在签到
        if((time() - $res['qian_dao_time'] > 24*60*60)){ // 判断时间是否大于24小时
          // 让字段归0
          $addInfo = $db -> update('qian_dao',array('qian_dao_num'=>1,'qian_dao_time'=>$time),array('uid'=>$uid));
        }else{
          // 更新签到的天数
          $addInfo = $db -> update('qian_dao',array('qian_dao_num[+]'=>1,'qian_dao_time'=>$time),array('uid'=>$uid));
        }
      }else{
        // echo '您还没有签到过';
        //没有签到过
        $db -> insert('qian_dao',array('uid'=>$uid,'qian_dao_num'=>1,'qian_dao_time'=>$time));
        // echo $db ->last_query();
      }
      // 插入签到记录
      $db -> insert('sign',array(
        'uid'=>$uid,
        'dateline'=>$time,
      ));
      // 获取连续签到的天数
      $info = $db -> get('qian_dao','qian_dao_num',array('uid'=>$uid));
      echo json_encode(array('state'=>'success','msg'=>"您是第".$info."天签到"));
      break;
    default :
      echo json_encode(array("ret"=>0,"msg"=>"操作不存在!"));
      break;
  }

sql:

CREATE TABLE IF NOT EXISTS `qian_dao` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `uid` int(1) NOT NULL COMMENT '用户id',
 `qian_dao_num` int(11) NOT NULL COMMENT '签到次数',
 `qian_dao_time` int(11) NOT NULL COMMENT '签到时间',
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `sign` (
 `uid` int(11) NOT NULL,
 `dateline` varchar(10) COLLATE utf8_bin NOT NULL,
 KEY `uid` (`uid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

html:

<" 00:00:00"); 
  $todayEnd= strtotime(date('Y-m-d')." 23:59:59"); 
  $isexit = $db -> get('qian_dao','id',array('AND'=>array('uid'=>$uid,'qian_dao_time[>=]'=>$todayBegin,'qian_dao_time[<=]'=>$todayEnd)));
  $flag = '';
  if($isexit){
    $flag = 'current';
  }
"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jquery制作每天或每日打卡签到特效</title>
<meta name="description" content="jquery制作论坛或社交网站的每日或每天打卡签到特效,点击打卡标签显示打卡签到效果。jquery下载" />
</head>
<body>
<style type="text/css">
*{margin:0;padding:0;list-style-type:none;}
a,img{border:0;text-decoration:none;}
/*今日签到*/
.singer{border:1px solid #DCDBDB;padding:10px;height:45px;line-height:45px;width:290px;margin:20px auto;}
.ul{border:1px solid #DCDBDB;padding:0 10px 10px 10px;;width:290px;margin:20px auto;}
.li{border:1px solid #DCDBDB;padding-left:10px;height:25px;line-height:25px;width:280px;margin:10px 0 0 0;}
.singer_l_cont, .singer_r_img{float:left;}
.singer_l_cont{width:145px;background:url(images/sing_per.gif) no-repeat left 12px;text-indent:23px;font-size:12px;}
.singer_r_img{display:block;width:114px;height:52px;background:url(images/sing_week.gif) right 2px no-repeat;vertical-align:middle;float:right;*margin-bottom:-10px;}
.singer_r_img:hover{background-position:right -53px;text-decoration:none;}
.singer_r_img span{margin-left:14px;font-size:16px;font-family:'Hiragino Sans GB','Microsoft YaHei',sans-serif !important;font-weight:700;color:#165379;}
.singer_r_img.current{background:url(images/sing_sing.gif) no-repeat 0 2px;}
</style>
  <div class="singer">
    <div class="singer_l_cont">
      <span>每天签到赢取PK币</span>
    </div>
    <div class="singer_r_r">
      <a class="singer_r_img <" href="#" rel="external nofollow" >    
        <span id="sing_for_number"></span>
      </a>
    </div>
  </div><!--singer end-->
<script src="/UploadFiles/2021-04-02/jquery.js">php+mysql数据库操作入门教程》、《php+mysqli数据库程序设计技巧总结》、《php面向对象程序设计入门教程》、《PHP数组(Array)操作技巧大全》、《php字符串(string)用法总结》及《php常见数据库操作技巧汇总》

希望本文所述对大家PHP程序设计有所帮助。

标签:
PHP,连续签到

无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com