| span style="color: #0000BB"><?php/*-- +MySQL-- Table structure for table `users`--CREATE TABLE IF NOT EXISTS `users` ( `user_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `session_id` varchar(32) NOT NULL, `session_expire` timestamp NULL DEFAULT NULL, PRIMARY KEY (`user_id`), KEY `session_id` (`session_id`), KEY `session_expire` (`session_expire`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=120 ;---- Dumping data for table `users`--INSERT INTO `users` (`user_id`, `session_id`, `session_expire`) VALUES(1, '12345', '2012-03-05 14:23:59');-- -MySQL*///define('SESSION_NAME', 'SID_CAPTCHA');//define('SESSION_NAME', 'SID_SPECIAL');define('SESSION_NAME', 'SID_DEFAULT');define('SESSION_EXPIRE', 129600);define('SESSION_PATH', DIRECTORY_SEPARATOR);define('SESSION_DOMAIN', ('.' . $_SERVER['HTTP_HOST']));define('SESSION_SECURE', false);define('SESSION_HTTPONLY', true);define('TIMESTAMP', 'Y-m-d H:i:s');//ini_set('display_errors', 1);//error_reporting(E_ALL);//include_once 'db.php'; //PDO Driver/*setCookie(SESSION_NAME, '12345', //Session value SESSION_EXPIRE + $_SERVER['REQUEST_TIME'], //Session lifetime SESSION_PATH, SESSION_DOMAIN, SESSION_SECURE, SESSION_HTTPONLY);*///$_COOKIE['someKey'] = 'someValue';session_name(SESSION_NAME);if (isset($_COOKIE[SESSION_NAME])) { session_start(); if (! isset($_SESSION['SELF'])) { $_SESSION = array(); $query = $db->prepare("SELECT `user_id` FROM `users` WHERE `session_id` = ? AND `session_expire` > NOW() LIMIT 1;"); //$query = $db->prepare("SELECT `user_id` FROM `users` WHERE `session_expire` > NOW() AND `session_id` = ? LIMIT 1;"); //$query = $db->prepare("SELECT `user_id` FROM `users` WHERE `session_expire` > '" . date(TIMESTAMP) . "' AND `session_id` = ? LIMIT 1;"); $query->execute(array($_COOKIE[SESSION_NAME])); if ($query->rowCount()) { $_SESSION['SELF'] = true; session_set_cookie_params(SESSION_EXPIRE, SESSION_PATH, SESSION_DOMAIN, SESSION_SECURE, SESSION_HTTPONLY); session_regenerate_id(true); $_SESSION += $query->fetch(); $query = $db->prepare("UPDATE `users` SET `session_expire` = NOW() + INTERVAL '" . SESSION_EXPIRE . "' SECOND, `session_id` = :new WHERE `session_id` = :old LIMIT 1;"); //$query = $db->prepare("UPDATE `users` SET `session_expire` = '" . date(TIMESTAMP, SESSION_EXPIRE + $_SERVER['REQUEST_TIME']) . "', `session_id` = :new WHERE `session_id` = :old LIMIT 1;"); $query->execute(array(':old' => $_COOKIE[SESSION_NAME], ':new' => $_COOKIE[SESSION_NAME] = session_id())); } else { session_destroy(); setCookie(SESSION_NAME, null, //Session value. 0, //Session expire. SESSION_PATH, SESSION_DOMAIN, SESSION_SECURE, SESSION_HTTPONLY); unSet($_COOKIE[SESSION_NAME]); } }}//*echo '<pre>';print_r($_COOKIE);print_r($_SESSION);echo '</pre>';//*/ |
|