濮阳杆衣贸易有限公司

主頁 > 知識庫 > PHP連續(xù)簽到功能實現(xiàn)方法詳解

PHP連續(xù)簽到功能實現(xiàn)方法詳解

熱門標(biāo)簽:百應(yīng)電話機器人服務(wù) 山西探意電話機器人 河南電銷卡外呼系統(tǒng)哪家強 山西回?fù)芡夂粝到y(tǒng) 岳陽外呼型呼叫中心系統(tǒng)在哪里 昭通辦理400電話 揚州地圖標(biāo)注app 青島語音外呼系統(tǒng)招商 騰訊外呼管理系統(tǒng)

本文實例講述了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)站的每日或每天打卡簽到特效,點擊打卡標(biāo)簽顯示打卡簽到效果。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(); // 緩存變量,當(dāng)數(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>nbsp;?php echo date('Y-m-d H:i:s',$v['dateline']);?>/li>
  ?php
    }
  }
  ?>
/ul>

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php+mysql數(shù)據(jù)庫操作入門教程》、《php+mysqli數(shù)據(jù)庫程序設(shè)計技巧總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計入門教程》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》及《php常見數(shù)據(jù)庫操作技巧匯總》

希望本文所述對大家PHP程序設(shè)計有所幫助。

您可能感興趣的文章:
  • thinkPHP實現(xiàn)簽到功能的方法
  • php+mysql+jquery實現(xiàn)日歷簽到功能
  • php實現(xiàn)每日簽到功能
  • php實現(xiàn)簽到功能的方法實例分析
  • 定位地理位置PHP判斷員工打卡簽到經(jīng)緯度是否在打卡之內(nèi)
  • PHP使用redis位圖bitMap 實現(xiàn)簽到功能
  • Php連接及讀取和寫入mysql數(shù)據(jù)庫的常用代碼
  • php中關(guān)于mysqli和mysql區(qū)別的一些知識點分析
  • PHP讀取MySQL數(shù)據(jù)代碼
  • PHP+MYSQL實現(xiàn)用戶的增刪改查
  • php基礎(chǔ)之連接mysql數(shù)據(jù)庫和查詢數(shù)據(jù)

標(biāo)簽:銅川 宜賓 鎮(zhèn)江 寶雞 湛江 黃南 南陽 婁底

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《PHP連續(xù)簽到功能實現(xiàn)方法詳解》,本文關(guān)鍵詞  PHP,連續(xù),簽到,功能,實現(xiàn),;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《PHP連續(xù)簽到功能實現(xiàn)方法詳解》相關(guān)的同類信息!
  • 本頁收集關(guān)于PHP連續(xù)簽到功能實現(xiàn)方法詳解的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    玉山县| 阿巴嘎旗| 天气| 左贡县| 浮梁县| 抚顺县| 泰宁县| 乌鲁木齐市| 平江县| 潜山县| 石柱| 莒南县| 柯坪县| 东港市| 沂南县| 吴川市| 札达县| 榆树市| 西安市| 彰化县| 盐池县| 安平县| 东乌珠穆沁旗| 吉安市| 讷河市| 辽阳县| 万全县| 于都县| 绥芬河市| 卓尼县| 贡嘎县| 绥宁县| 沭阳县| 丹巴县| 潢川县| 乌拉特后旗| 富裕县| 浠水县| 新巴尔虎右旗| 永昌县| 乌兰县|