_id = $this->_getUserId(); if ($this->_id != false) { $this->_time = time(); $this->_lifetime = 60 * 60 * 24 * 90 + time(); // 3 month cookie time $this->_getSessionData(); $this->count = count($this->_data); if ((date('j') == 1) || (date('j') == 15)) $this->_cleanup(); } } //see if info is already in data function checkData($data) { (@in_array($data, $this->_data)) ? $result = true : $result = false; return $result; } //set session data in db function setData($index ='', $data = '') { global $wpdb; $ip = $_SERVER['REMOTE_ADDR']; if ($this->count == 0) $wpdb->query("INSERT INTO tv_sessions(id, time) values('$this->_id', NOW())"); $result = $this->checkData($this->newData); //if cookie can't be set then return false if (!($result)) { if ($index =='') { ($this->index=='') ? $index = count($this->_data) : $index = $this->index; $this->_data[$index] = $this->newData; } else { $this->_data[$index] = $data; } $data = serialize($this->_data); $wpdb->query("UPDATE `tv_sessions` SET `data`='$data', `time`=NOW(), `ip`='$ip' WHERE `id`='$this->_id'"); } return $result; } //test cookie setting function testCookie() { ($_COOKIE['uid']=='') ? $set = false : $set = true; return $set; } //get or set session user_id function _getUserId() { if ($_COOKIE['uid']=='') { $id = md5(uniqid(rand(), true)); if (!(setcookie('uid', $id, $this->_lifetime, '/'))) $id = false; } else { $id = $_COOKIE['uid']; } return $id; } function getData($index = '') { ($index == '') ? $data = $this->_data : $data = $this->_data[$index]; return $data; } //get user session data from user_id function _getSessionData() { global $wpdb; $data = @unserialize($wpdb->get_var("SELECT data FROM `tv_sessions` WHERE id='$this->_id'")); //if not array return empty array (is_array($data)) ? $this->_data = $data : $this->_data = array(); } function _cleanup() { global $wpdb; // delete if inactive for 3 months $wpdb->query("DELETE FROM tv_sessions WHERE ADDTIME(time, '2160:00:00') < NOW()"); } } //initialize tv_session if ($_ENV['HTTP_HOST']!='') $tvs = new tvSession(); ?> Find Your Inspiration | Tivate.com '); ?>
A A A
>







Page 1 of 4912345678»  Last »