您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關使用PHP怎么實現一個連續簽到功能,文章內容質量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關知識有一定的了解。
具體如下:
require "./global.php"; $act = isset($_GET['act']) ? $_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:
<?php include './global.php'; $uid = 1; $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))); $flag = ''; if($isexit){ $flag = 'current'; } ?> <!DOCTYPE html PUBLIC "-//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 <?php echo $flag;?>" href="#" rel="external nofollow" > <span id="sing_for_number"></span> </a> </div> </div><!--singer end--> <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script> <script type="text/javascript"> /*簽到模塊日期捕捉:*/ function week(){ var objDate= new Date(); var week = objDate.getDay(); switch(week) { case 0: week="周日"; break; case 1: week="周一"; break; case 2: week="周二"; break; case 3: week="周三"; break; case 4: week="周四"; break; case 5: week="周五"; break; case 6: week="周六"; break; } $("#sing_for_number").html( week ); } $(document).ready(function(){ week(); var cache=new Array(); // 緩存變量,當數據被訪問過之后放置在緩存中,加快訪問速度 $(".singer_r_img").click(function(){ // 如果緩存中存在數據,那么直接從緩存中讀取;如果不存在數據,那么就從數據庫中讀取,并把數據存入緩存 if (typeof(cache['stop'])=='undefined') { $.ajax({ url:"action.php?act=qiandao", type:"post", dataType:'json', data:{ uid:1, }, async:false, success:function(data){ // alert(data.msg); switch(data.state){ case 'success': alert(data.msg); break case 'stop': cache['stop'] = data.msg; alert(data.msg); break; } $(".singer_r_img").addClass("current"); } }) }else{ alert(cache['stop']) } }) }) </script> </body> </html> <?php // 獲取簽到記錄 $sign = $db -> select('sign','*',array('uid'=>$uid,'ORDER'=>'dateline DESC')); ?> <ul class='ul'> <?php if(empty($sign)){ ?> <li class="li">暫無簽到信息</li> <?php }else{ foreach($sign as $k=>$v){ ?> <li class="li"><span><?php echo ($k + 1);?></span> <?php echo date('Y-m-d H:i:s',$v['dateline']);?></li> <?php } } ?> </ul>
關于使用PHP怎么實現一個連續簽到功能就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。