예제 #1
0
/* ------------------------------------------------------------------------------------------------ */
// Detect Guest's IP Address and Insert new records
$ip = "0.0.0.0";
if (!empty($_SERVER['REMOTE_ADDR'])) {
    $ip = $_SERVER['REMOTE_ADDR'];
}
// Determine Date/Time Now
// Pls see >> http://groups.drupal.org/node/4838#comment-14101 - time() or mktime() or gmmktime()
$now = mktime();
// Now we are checking if the ip was logged in the database.
// Depending of the value in minutes in the iplifetime variable.
// Check session time, insert new record if timeout
modVisitCounterHelper::insertVisitor($iplifetime, $ip, $now);
// Update Date/Time Now
$now = mktime();
$datetime =& modVisitCounterDateTime::getTimeStart($offset, $issunday, $now);
$daystart = $datetime["daystart"];
$local_daystart = $datetime["local_daystart"];
$yesterdaystart = $datetime["yesterdaystart"];
$local_yesterdaystart = $datetime["local_yesterdaystart"];
$weekstart = $datetime["weekstart"];
$local_weekstart = $datetime["local_weekstart"];
$lweekstart = $datetime["lweekstart"];
$local_lweekstart = $datetime["local_lweekstart"];
$monthstart = $datetime["monthstart"];
$local_monthstart = $datetime["local_monthstart"];
$lmonthstart = $datetime["lmonthstart"];
$local_lmonthstart = $datetime["local_lmonthstart"];
/* ------------------------------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------------------------------ */
// BEGIN: Caculate number visitors of Today, Yesterday, This Week, Last Week, This Month, Last Month
예제 #2
0
 function &getTimeStart($offset = 0, $issunday = true, $now = "")
 {
     $offset = (double) $offset;
     $now = (int) $now;
     if (empty($now)) {
         $now = mktime();
     }
     /* ------------------------------------------------------------------------------------------------ */
     // Determine GMT Time (UTC+00:00)
     // Determine this minute, this hour, this day, this month, this year
     // Don't use strftime()
     $minute = (int) gmstrftime("%M", $now);
     $hour = (int) gmstrftime("%H", $now);
     $day = (int) gmstrftime("%d", $now);
     $month = (int) gmstrftime("%m", $now);
     $year = (int) gmstrftime("%Y", $now);
     // Determine Starting GMT Time and Local Time of Today
     $daystart = gmmktime(0, 0, 0, $month, $day, $year);
     $local_daystart = modVisitCounterDateTime::localTimeStart($daystart, $offset, "day");
     // Determine Starting GMT Time and Local Time of Yesterday
     // $yesterdaystart		=	strtotime( "-1 day", $daystart ) ;
     $yesterdaystart = $daystart - 86400;
     $local_yesterdaystart = $local_daystart - 86400;
     // Determine Starting GMT Time and Local Time of This Week
     // If Sunday is starting day of week then Sunday = 0 ... Saturday = 6
     // If Monday is starting day of week then Monday = 0 ... Sunday = 6
     $weekday = (int) strftime("%w", $now);
     if (!$issunday) {
         if ($weekday) {
             $weekday--;
         } else {
             $weekday = 6;
         }
     }
     $weekstart = $daystart - $weekday * 86400;
     $local_weekstart = modVisitCounterDateTime::localTimeStart($weekstart, $offset, "week");
     // Starting Starting GMT Time and Local Time of Last Week
     $lweekstart = $weekstart - 7 * 86400;
     $local_lweekstart = $local_weekstart - 7 * 86400;
     // Determine Starting GMT Time and Local Time of This Month
     $monthstart = gmmktime(0, 0, 0, $month, 1, $year);
     $local_monthstart = modVisitCounterDateTime::localTimeStart($monthstart, $offset, "month");
     // Determine Starting GMT Time and Local Time of Last Month
     // $days_lmonth: Number days of last month (28/29, 30 or 31)
     $days_lmonth = (int) strftime("%d", $monthstart - 86400);
     $lmonthstart = $monthstart - $days_lmonth * 86400;
     $local_lmonthstart = $local_monthstart - $days_lmonth * 86400;
     $datetime = array();
     $datetime["daystart"] = $daystart;
     $datetime["local_daystart"] = $local_daystart;
     $datetime["yesterdaystart"] = $yesterdaystart;
     $datetime["local_yesterdaystart"] = $local_yesterdaystart;
     $datetime["weekstart"] = $weekstart;
     $datetime["local_weekstart"] = $local_weekstart;
     $datetime["lweekstart"] = $lweekstart;
     $datetime["local_lweekstart"] = $local_lweekstart;
     $datetime["monthstart"] = $monthstart;
     $datetime["local_monthstart"] = $local_monthstart;
     $datetime["lmonthstart"] = $lmonthstart;
     $datetime["local_lmonthstart"] = $local_lmonthstart;
     return $datetime;
 }