public function __construct() { parent::__construct(); $this->db->where('remember_me', FALSE)->where('UNIX_TIMESTAMP(last_activity) <', time() - strtoseconds($this->config->nf_cookie_expire))->delete('nf_sessions'); $this->_ip_address = isset($_SERVER['HTTP_X_REAL_IP']) ? $_SERVER['HTTP_X_REAL_IP'] : $_SERVER['REMOTE_ADDR']; $this->_host_name = utf8_string(gethostbyaddr($this->_ip_address)); if (isset($_COOKIE[$this->config->nf_cookie_name]) && $this->_check_cookie($cookie = $_COOKIE[$this->config->nf_cookie_name], $last_activity)) { if (strtotime($this->config->nf_cookie_expire, $last_activity) < time()) { $this->_session_id(); } else { $this->_session_id = $cookie; } $this->db->where('session_id', $cookie)->update('nf_sessions', array('session_id' => $this->_session_id, 'ip_address' => $this->_ip_address, 'host_name' => $this->_host_name, 'last_activity' => now())); if (!is_null($time_zone = $this('session', 'time_zone'))) { set_time_zone($time_zone); $this->db->update_time_zone(); } } else { if (!is_asset() && !$this->config->ajax_url && !$this->config->ajax_header && $_SERVER['REQUEST_METHOD'] != 'OPTIONS') { $this->_session_id(); $crawler = is_crawler(); if ($crawler !== FALSE) { $this->db->insert('nf_crawlers', array('name' => $crawler, 'path' => $this->config->request_url)); } $this->db->insert('nf_sessions', array('session_id' => $this->_session_id, 'ip_address' => $this->_ip_address, 'host_name' => $this->_host_name, 'is_crawler' => $crawler !== FALSE)); $this->_user_data['session']['date'] = time(); $this->_user_data['session']['javascript'] = FALSE; $this->_user_data['session']['referer'] = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; $this->_user_data['session']['user_agent'] = $_SERVER['HTTP_USER_AGENT']; } } statistics('nf_sessions_max_simultaneous', $this->_sessions = $this->db->select('COUNT(DISTINCT IFNULL(user_id, session_id))')->from('nf_sessions')->where('last_activity > DATE_SUB(NOW(), INTERVAL 5 MINUTE)')->where('is_crawler', FALSE)->row(), function ($a, $b) { return $a > $b; }); }
function timetostr($format, $timestamp = NULL) { if (is_null($timestamp)) { $timestamp = time(); } if (!is_numeric($timestamp)) { $timestamp = strtotime($timestamp); } if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { $format = preg_replace('#(?<!%)((?:%%)*)%e#', '\\1%#d', $format); } return utf8_string(ucfirst(strtolower(strftime($format, $timestamp)))); }
/** * utf8_str_sort( ) * * Sort all characters according to code points * @since 1.2 * * @param string $str UTF-8 string * @param bool $unique Sort unique. If true, repeated characters are ignored * @param bool $desc If true, will sort characters in reverse code point order. * @return string String of sorted characters */ function utf8_str_sort($str, $unique = false, $desc = false) { $array = utf8_codepoints($str); if ($unique) { $array = array_flip(array_flip($array)); } if ($desc) { arsort($array); } else { asort($array); } return utf8_string($array); }