PHP連續(xù)簽到功能實現(xiàn)方法詳解
本文實例講述了PHP連續(xù)簽到功能實現(xiàn)方法。分享給大家供大家參考,具體如下:
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{ // 更新簽到的天數(shù) $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, )); // 獲取連續(xù)簽到的天數(shù) $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 '簽到次數(shù)', `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制作論壇或社交網(wǎng)站的每日或每天打卡簽到特效,點擊打卡標簽顯示打卡簽到效果。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="/a1/uploads/allimg/200111/10042H441-0.jpg"></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(); // 緩存變量,當數(shù)據(jù)被訪問過之后放置在緩存中,加快訪問速度 $(".singer_r_img").click(function(){ // 如果緩存中存在數(shù)據(jù),那么直接從緩存中讀??;如果不存在數(shù)據(jù),那么就從數(shù)據(jù)庫中讀取,并把數(shù)據(jù)存入緩存 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相關內(nèi)容感興趣的讀者可查看本站專題:《php+mysql數(shù)據(jù)庫操作入門教程》、《php+mysqli數(shù)據(jù)庫程序設計技巧總結(jié)》、《php面向?qū)ο蟪绦蛟O計入門教程》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家PHP程序設計有所幫助。
上一篇:Laravel框架Eloquent ORM簡介、模型建立及查詢數(shù)據(jù)操作詳解
欄 目:PHP編程
下一篇:設定php簡寫功能的方法
本文標題:PHP連續(xù)簽到功能實現(xiàn)方法詳解
本文地址:http://mengdiqiu.com.cn/a1/PHPbiancheng/11070.html
您可能感興趣的文章
- 04-02關于txt數(shù)據(jù)庫php的信息
- 04-02php本站才可以請求數(shù)據(jù) php本地數(shù)據(jù)庫
- 04-02網(wǎng)頁里php操作數(shù)據(jù)庫 php網(wǎng)頁例子
- 04-02php打印請求數(shù)據(jù) php打印輸出結(jié)果
- 04-02php數(shù)據(jù)庫地址 phpstudy 數(shù)據(jù)庫
- 04-02php插入數(shù)據(jù)庫為亂碼 php連接數(shù)據(jù)庫亂碼
- 04-02php數(shù)據(jù)庫數(shù)據(jù)相加 php數(shù)據(jù)庫添加數(shù)據(jù)語句
- 04-02php數(shù)據(jù)庫輸入變量 php里輸出數(shù)據(jù)庫數(shù)據(jù)函數(shù)
- 04-02數(shù)據(jù)權限架構(gòu)思路php 數(shù)據(jù)權限設計方案
- 04-02php如何用導入數(shù)據(jù) php用來導入其他文件的語句


閱讀排行
本欄相關
- 04-02php本站才可以請求數(shù)據(jù) php本地數(shù)據(jù)庫
- 04-02關于txt數(shù)據(jù)庫php的信息
- 04-02php打印請求數(shù)據(jù) php打印輸出結(jié)果
- 04-02網(wǎng)頁里php操作數(shù)據(jù)庫 php網(wǎng)頁例子
- 04-02php插入數(shù)據(jù)庫為亂碼 php連接數(shù)據(jù)庫亂
- 04-02php數(shù)據(jù)庫地址 phpstudy 數(shù)據(jù)庫
- 04-02php數(shù)據(jù)庫數(shù)據(jù)相加 php數(shù)據(jù)庫添加數(shù)據(jù)
- 04-02數(shù)據(jù)權限架構(gòu)思路php 數(shù)據(jù)權限設計方
- 04-02php數(shù)據(jù)庫輸入變量 php里輸出數(shù)據(jù)庫數(shù)
- 04-02php如何用導入數(shù)據(jù) php用來導入其他文
隨機閱讀
- 01-10SublimeText編譯C開發(fā)環(huán)境設置
- 01-10C#中split用法實例總結(jié)
- 08-05DEDE織夢data目錄下的sessions文件夾有什
- 01-11ajax實現(xiàn)頁面的局部加載
- 08-05織夢dedecms什么時候用欄目交叉功能?
- 01-10delphi制作wav文件的方法
- 08-05dedecms(織夢)副欄目數(shù)量限制代碼修改
- 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
- 04-02jquery與jsp,用jquery
- 01-10使用C語言求解撲克牌的順子及n個骰子