Beispiel #1
0
 public function write($sess_id, $sess_data)
 {
     global $user;
     // If saving of session data is disabled or if the client doesn't have a session,
     // and one isn't being created ($value), do nothing. This keeps crawlers out of
     // the session table. This reduces memory and server load, and gives more useful
     // statistics. We can't eliminate anonymous session table rows without breaking
     // the throttle module and the "Who's Online" block.
     //if (!$this->is_save_session() || ($user->uid == 0 && empty($_COOKIE[session_name()]) && empty($sess_data))) {
     if (!$this->is_save_session() || empty($_COOKIE[session_name()]) && empty($sess_data)) {
         return TRUE;
     }
     $sess_key = $this->_prefix . $sess_id;
     $sessinfo = array('uid' => $user->uid, 'lastip' => get_clientip(), 'session' => $sess_data);
     $this->_mm->set($sess_key, $sessinfo, 0, $this->_lifetime);
     if ($user->uid) {
         // just record logined user
         $online_key = $this->_prefix . 'online_users';
         $online_users = $this->_mm->get($online_key);
         if (empty($online_users)) {
             $online_users = array('u' . $user->uid => $this->_timestamp);
             $this->_mm->set($online_key, $online_users, 0, 0);
         } else {
             $online_users['u' . $user->uid] = $this->_timestamp;
             $this->_mm->replace($online_key, $online_users, 0, 0);
         }
     }
     return TRUE;
 }
Beispiel #2
0
 public function write($sess_id, $sess_data)
 {
     global $user;
     // If saving of session data is disabled or if the client doesn't have a session,
     // and one isn't being created ($value), do nothing. This keeps crawlers out of
     // the session table. This reduces memory and server load, and gives more useful
     // statistics. We can't eliminate anonymous session table rows without breaking
     // the throttle module and the "Who's Online" block.
     if (!$this->is_save_session() || empty($_COOKIE[session_name()]) && empty($sess_data)) {
         return TRUE;
     }
     $this->_db->query("UPDATE `{$this->_dbtable}` SET `uid`=%d, `lasttime`=%d, `lastip`='%s', `data`='%s' WHERE `sid`='%s'", $user->uid, $this->_timestamp, get_clientip(), $sess_data, $sess_id);
     if (!$this->_db->affected_rows()) {
         //update error, indicating no the session
         $this->_db->query("INSERT INTO `{$this->_dbtable}` (`sid`, `uid`, `lasttime`, `lastip`, `data`) VALUES('%s', %d, %d, '%s', '%s')", $sess_id, $user->uid, $this->_timestamp, get_clientip(), $sess_data);
     }
     return TRUE;
 }
Beispiel #3
0
 /**
  * Request user ip
  */
 public static function ip()
 {
     return get_clientip();
 }
Beispiel #4
0
/**
 * new insert or update `{visiting}` table
 *
 * if $url is a numeric, then for editing;
 * else for new insert, while $url is a string.
 *
 * @param mixed $url
 *   may be a url or a numeric id
 * @param array $params
 *   containing browser extra info, for example:
 *   $params['browserName']
 *   $params['browserVersion']
 *   $params['browserCodeName']
 *   $params['browserLanguage']
 *   $params['userAgent']
 *   $params['osPlatform']
 *   $params['cookieEnabled']
 *   $params['javaEnabled']
 *   $params['screenWxH']
 *   $params['screenColor']
 *   $params['screenPixelRatio']
 *   $params['screenOrientation']
 *   $params['winOrientation']
 *   $params['flashVersion']
 *   $params['referrer']
 *   $params['uvid']
 *   $params['uid']
 *   $params['cflag1']
 *   $params['cflag2']
 *   $params['cflag3']
 *   $params['status']
 *   $params['retentionTime']
 *  @param string $action
 */
function V($url = '', $params = array(), $action = 'poststatus')
{
    $vid = 0;
    if (is_numeric($url)) {
        // for editing
        $vid = $url;
        if (!!$vid) {
            switch ($action) {
                case 'onload_stat':
                    $onload_time = isset($params['onloadTime']) ? intval($params['onloadTime']) : 0;
                    $vinfo = array('onload_time' => $onload_time, 'changed' => time());
                    D()->update_table('visiting', $vinfo, array('vid' => $vid));
                    break;
                case 'retention_stat':
                    $retention_time = isset($params['retentionTime']) ? intval($params['retentionTime']) : 0;
                    $vinfo = array('retention_time' => $retention_time, 'changed' => time());
                    D()->update_table('visiting', $vinfo, array('vid' => $vid));
                    break;
                case 'poststatus':
                    $uid = isset($params['uid']) ? intval($params['uid']) : 0;
                    $status = isset($params['status']) ? trim($params['status']) : 'R';
                    $vinfo = array('uid' => $uid, 'changed' => time(), 'status' => $status);
                    D()->update_table('visiting', $vinfo, array('vid' => $vid));
                    break;
            }
        }
    } else {
        // for new insert
        $ip = get_clientip();
        $locaid = 0;
        $locacity = '';
        //try to find location by ip
        //$ipinfo   = ip_save($ip, ip_convert($ip));
        if (!empty($ipinfo['location']) && !empty($ipinfo['locaid'])) {
            $locaid = $ipinfo['locaid'];
            $locacity = $ipinfo['location'];
        }
        $uid = isset($params['uid']) ? $params['uid'] : 0;
        $browserName = isset($params['browserName']) ? $params['browserName'] : '';
        $browserVersion = isset($params['browserVersion']) ? $params['browserVersion'] : '';
        $browserCodeName = isset($params['browserCodeName']) ? $params['browserCodeName'] : '';
        $cookieEnabled = isset($params['cookieEnabled']) ? $params['cookieEnabled'] : 0;
        $javaEnabled = isset($params['javaEnabled']) ? $params['javaEnabled'] : 0;
        $userAgent = isset($params['userAgent']) ? $params['userAgent'] : $_SERVER['HTTP_USER_AGENT'];
        $osPlatform = isset($params['osPlatform']) ? $params['osPlatform'] : '';
        $screenWxH = isset($params['screenWxH']) ? $params['screenWxH'] : '';
        $screenColor = isset($params['screenColor']) ? $params['screenColor'] : 0;
        $flashVersion = isset($params['flashVersion']) ? $params['flashVersion'] : '';
        $referrer = isset($params['referrer']) ? $params['referrer'] : '';
        $cflag1 = isset($params['cflag1']) ? $params['cflag1'] : '';
        $cflag2 = isset($params['cflag2']) ? $params['cflag2'] : '';
        $cflag3 = isset($params['cflag3']) ? $params['cflag3'] : '';
        $uv = !empty($params['uvid']) ? $params['uvid'] : md5($ip . $userAgent);
        //uv = md5(ip + userAgent)
        $now = time();
        $vinfo = array('uid' => $uid, 'targeturl' => $url, 'referurl' => $referrer, 'uv' => $uv, 'ip' => $ip, 'locaid' => $locaid, 'locacity' => $locacity, 'user_agent' => $userAgent, 'browser_name' => $browserName, 'browser_ver' => $browserVersion, 'browser_core' => $browserCodeName, 'browser_lang' => $params['browserLanguage'], 'os_platform' => $osPlatform, 'is_cookie' => $cookieEnabled, 'is_java' => $javaEnabled, 'screen_color' => $screenColor, 'screen_wxh' => $screenWxH, 'screen_pxratio' => $params['screenPixelRatio'], 'screen_orientation' => $params['screenOrientation'], 'window_orientation' => $params['winOrientation'], 'flash_ver' => $flashVersion, 'cflag1' => $cflag1, 'cflag2' => $cflag2, 'cflag3' => $cflag3, 'created' => $now, 'changed' => $now, 'status' => 'N');
        $vid = D()->insert_table('visiting', $vinfo);
    }
    return $vid;
}
 /**
  * Generates a default anonymous $user object.
  *
  * @param object $_user
  * @param string $_session
  * @return object - the user object.
  */
 public static function anonymous_user($_user, $_session = '')
 {
     $_user->uid = 0;
     $_user->lastip = get_clientip();
     $_user->cached = array();
     $_user->session = $_session;
     return $_user;
 }