Example #1
0
 /**
  * 解密客户端秘钥,获取用户数据
  */
 private function deciphering_user_info()
 {
     //获取加密身份标示
     $identity_encryption = $this->_post('user_key');
     //	$identity_encryption = $this->_get('user_key');
     //$identity_encryption = "CGsAOQdmDDMNNlQ0BTAEPgQ0AWpRNlFgC2hXb1IxVzBVNVNkBXgCPllkAnkDNwU1";
     //解密获取用户数据
     $decrypt = passport_decrypt($identity_encryption, C('UNLOCAKING_KEY'));
     $user_info = explode(':', $decrypt);
     $uid = $user_info[0];
     //用户id
     $account = $user_info[1];
     //用户账号
     $date = $user_info[2];
     //账号时间
     //安全过滤
     if (count($user_info) < 3) {
         $this->callback(C('STATUS_OTHER'), '身份验证失败');
     }
     if (countDays($date, date('Y-m-d'), 1) >= 30) {
         $this->callback(C('STATUS_NOT_LOGIN'), '登录已过期,请重新登录');
     }
     //钥匙过期时间为30天
     //去数据库获取用户数据
     $user_data = D('Users')->field('id,account,type,name')->where(array('id' => $uid, 'status' => 0))->find();
     if (empty($user_data)) {
         $this->callback(C('STATUS_NOT_DATA'), '此用户不存在,或被禁用');
     } else {
         $this->oUser = (object) $user_data;
     }
 }
Example #2
0
<?php

//ini_set('memory_limit', '2048M');
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(-1);
function countDays($dateInString)
{
    $mo = substr($dateInString, 0, 2);
    $day = substr($dateInString, 3, 2);
    $yr = substr($dateInString, 6, 4);
    //if (checkdate($mo, $day, $yr)) {
    echo strtotime("{$mo}.{$day}.{$yr}");
    //}
}
countDays("01.15.2014");
function calCalendar($year, $month, $day = 0)
{
    $sundayStart = MODULE_CALENDAR_START_SUNDAY == 'true';
    $calendar = array();
    $calendar['year'] = $year;
    $calendar['month'] = $month;
    $calendar['today'] = -1;
    // 週のタイトル作成
    if ($sundayStart) {
        // 日曜が始め
        $week_header = array(MODULE_CALENDAR_SUN, MODULE_CALENDAR_MON, MODULE_CALENDAR_TUE, MODULE_CALENDAR_WED, MODULE_CALENDAR_THU, MODULE_CALENDAR_FRI, MODULE_CALENDAR_SAT);
        $week_style = array("w0", "w1", "w2", "w3", "w4", "w5", "w6");
    } else {
        $week_header = array(MODULE_CALENDAR_MON, MODULE_CALENDAR_TUE, MODULE_CALENDAR_WED, MODULE_CALENDAR_THU, MODULE_CALENDAR_FRI, MODULE_CALENDAR_SAT, MODULE_CALENDAR_SUN);
        $week_style = array("w1", "w2", "w3", "w4", "w5", "w6", "w0");
    }
    $calendar['week_header'] = $week_header;
    $calendar['week_style'] = $week_style;
    $dayCount = countDays($year, $month);
    $weekOffset = weekNo($year, $month, 1);
    $calendarDay = array();
    $calendarAttr = array();
    $calendarOpen = array();
    // 1日までの空白計算
    if ($sundayStart) {
        // 日曜が始め
        for ($i = 0; $i < $weekOffset; $i++) {
            $calendarDay[] = 0;
            $calendarAttr[] = "d" . $i;
            $calendarOpen[] = 0;
        }
    } else {
        $week = $weekOffset - 1;
        if ($week < 0) {
            $week = 6;
        }
        for ($i = 0; $i < $week; $i++) {
            $calendarDay[] = 0;
            $calendarAttr[] = "d" . ($i + 1) % 7;
            $calendarOpen[] = 0;
        }
    }
    // 日付計算
    $nowyear = date('Y');
    $nowmonth = date('m');
    $nowday = date('d');
    for ($i = 1; $i <= $dayCount; $i++) {
        $isOpen = isOpen($year, $month, $i);
        $rest = $isOpen ? "" : "rest";
        $calendarDay[] = $i;
        if ($year == $nowyear && $month == $nowmonth && $i == $nowday) {
            $calendarAttr[] = $rest . "today";
            $calendar['today'] = count($calendarDay) - 1;
            $calendarOpen[] = $isOpen;
        } else {
            $calendarAttr[] = $rest . "d" . $weekOffset;
            $calendarOpen[] = $isOpen;
        }
        $weekOffset = ($weekOffset + 1) % 7;
    }
    $calendarLine = ceil(count($calendarDay) / 7);
    // 月末以降の空白
    $n = count($calendarDay);
    for ($i = $n; $i < $calendarLine * 7; $i++) {
        $calendarDay[] = 0;
        $calendarAttr[] = "d" . $weekOffset;
        $weekOffset = ($weekOffset + 1) % 7;
    }
    $calendar['calendarLine'] = $calendarLine;
    $calendar['calendarDay'] = $calendarDay;
    $calendar['calendarAttr'] = $calendarAttr;
    $calendar['calendarOpen'] = $calendarOpen;
    return $calendar;
}
Example #4
0
	<!--      Question: Counts Days
						Write a function named countDays which takes a single parameter named dateinstring which is string in 
						the form ”MM.DD.YYY” represent a real date value. The function should print to the console the number 
						of days from the beginning of the year specified in dateInString until the date represented in 
						dateInString. If the value of dateInString is invalid, the function should print ”Bad format” to the 
						console. -->

<?php 
function countDays($dateInString)
{
    $date = explode('.', $dateInString);
    if (count($date) == 3 && checkdate($date[0], $date[1], $date[2])) {
        $formatted_date = $date[2] . '-' . $date[0] . '-' . $date[1] . ' 00:00:00';
        $diff = strtotime($formatted_date);
        $n = strtotime($date[2] . '-01-01 00:00:00');
        $s = $diff - $n;
        echo round($s / 86400) + 1;
    } else {
        echo 'Bad format';
    }
}
countDays('09.16.2014');