Re: [PHP] Customized Session Handler can not work for PHP 5.1.6 and CentOS 5.5
Hi, Thanks, it's originally is /var/lib/php/session, I double it's privilege problem, so changed to /tmp. And I Followed your advice for setenforce off, but can't make it work. Mingda On 2012/4/16 14:13, Alain Williams wrote: On Sun, Apr 15, 2012 at 12:27:00AM +0800, Mingda wrote: Hi, All, System: CentOS 5.5; PHP version is 5.1.6. I met a strange problem associate with session_save_handler in current environment(The same code can work well in my local windows platform and ubuntu system). I just want to use a customized session save handler to be triggered, so that I can call my own logic to handling the session. The testing in local is pretty great but when migration to the VPS, it bring me the following error: Fatal error: session_start() [function.session-start]: Failed to initialize storage module: user (path: /tmp) The default value for session save handler and session save path in php.ini are: session.save_handler = files session.save_path = "/tmp" session.name = PHPSESSID Try changing the path to /var/lib/php/session Are you being caught by selinux - try setenforce off and see if that makes it work. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Customized Session Handler can not work for PHP 5.1.6 and CentOS 5.5
On Sun, Apr 15, 2012 at 12:27:00AM +0800, Mingda wrote: > Hi, All, > > System: CentOS 5.5; PHP version is 5.1.6. > > I met a strange problem associate with session_save_handler in current > environment(The same code can work well in my local windows platform and > ubuntu system). > > I just want to use a customized session save handler to be triggered, so > that I can call my own logic to handling the session. The testing in > local is pretty great but when migration to the VPS, it bring me the > following error: > > Fatal error: session_start() [ href='function.session-start'>function.session-start]: Failed to > initialize storage module: user (path: /tmp) > > > The default value for session save handler and session save path in > php.ini are: > > session.save_handler = files > session.save_path = "/tmp" > session.name = PHPSESSID Try changing the path to /var/lib/php/session Are you being caught by selinux - try setenforce off and see if that makes it work. -- Alain Williams Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer. +44 (0) 787 668 0256 http://www.phcomp.co.uk/ Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php #include -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Customized Session Handler can not work for PHP 5.1.6 and CentOS 5.5
On Sat, Apr 14, 2012 at 9:27 AM, Mingda wrote: > Hi, All, > > System: CentOS 5.5; PHP version is 5.1.6. > > I met a strange problem associate with session_save_handler in current > environment(The same code can work well in my local windows platform and > ubuntu system). > This is your clue on how to fix. What version of PHP are on Windows and Ubuntu? If different, perhaps upgrade your CentOS' PHP? If the same exact version on all 3 OSes, then consult CentOS :). HTH, Tommy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Customized Session Handler can not work for PHP 5.1.6 and CentOS 5.5
Hi, All, System: CentOS 5.5; PHP version is 5.1.6. I met a strange problem associate with session_save_handler in current environment(The same code can work well in my local windows platform and ubuntu system). I just want to use a customized session save handler to be triggered, so that I can call my own logic to handling the session. The testing in local is pretty great but when migration to the VPS, it bring me the following error: Fatal error: session_start() [href='function.session-start'>function.session-start]: Failed to initialize storage module: user (path: /tmp) The default value for session save handler and session save path in php.ini are: session.save_handler = files session.save_path = "/tmp" session.name = PHPSESSID And the bottom are the code for the session handler. I first called ob_start(), and after calling session::init(), I called session_start(). Then the fatal error happen. It did not trigger any function in the "session" class. I tried change the php.ini from session.save_handler = user, but the error remains. And I found no matter what session.save_handler type is, after calling session_set_save_handler(), the session.save_handler will always automatically changed to 'user', that's why the Fatal error info shows user (path: /tmp). Can anybody help me out for such error? I was stuck by this issue for more than 2 days, but still haven't get any clue! You can view more details from stackoverflow if you want. Here is the link: http://stackoverflow.com/questions/8845924/session-set-save-handler-class-for-database-not-working session_set_save_handler('session::open', 'session::close', 'session::read', 'session::write', 'session::destroy', 'session::gc'); } public static function open($save_path, $session_name) { if (!is_dir($save_path)) { mkdir($save_path, 0777); } return true; } public static function close() { return true; } public static function read($sid) { global $db, $user; register_shutdown_function('session_write_close'); if (!isset($_COOKIE[session_name()])) { $user = anonymousUser($sid); return ''; } $result = $db->query('SELECT s.data as session_data, s.* , u.* FROM users u INNER JOIN sessions s ON u.uid = s.uid WHERE s.sid = "' . $db->escape($sid) . '" AND timestamp >= ' . $db->escape(TIMESTAMP - Bl_Config::get('session.lifetime', 10800))); $user = $result->row(); if ($user) { $data = $user->session_data; unset($user->passwd, $user->session_data); if ($user->uid > 0 && $user->status == 1) { $userInstance = User_Model::getInstance(); $user->roles = $userInstance->getUserRoles($user->uid); $user->roles[] = User_Model::ROLE_AUTHENTICATED_USER; $user->permissions = array(); $user->data = (isset($user->data) && $user->data) ? unserialize($user->data) : array(); foreach ($user->roles as $rid) { $user->permissions = array_merge($user->permissions, $userInstance->getRolePermissions($rid)); } $user->permissions = array_unique($user->permissions); } else { $user = anonymousUser($sid); } return $data; } else { $user = anonymousUser($sid); return ''; } } public static function write($sid, $data) { global $db, $user; if (!isset($user) || ($user->uid == 0 && empty($_COOKIE[session_name()]) && empty($data))) { return true; } $uri = '/' . Bl_Core::getUri(); $db->exec('UPDATE sessions SET uid = ' . $db->escape($user->uid) . ', ip = "' . $db->escape(ipAddress()) . '", uri = "' . $db->escape($uri) . '", data = "' . $db->escape($data) . '", timestamp = ' . $db->escape(TIMESTAMP) . ' WHERE sid = "' . $db->escape($sid) . '"'); if (!$db->affected()) { $db->exec('INSERT IGNORE INTO sessions (sid, uid, ip, uri, data, timestamp) VALUES ("' . $db->escape($sid) . '", ' . $db->escape($user->uid) . ', "' . $db->escape(ipAddress()) . '", "' . $db->escape($uri) . '", "' . $db->escape($data) . '", ' . $db->escape(TIMESTAMP) . ')'); } return true; } public static function destroy($sid) { global $db; $db->exec('DELETE FROM sessions WHERE sid = "' . $db->escape($sid) .. '"'); return true; } public static function gc($lifetime) { global $db; $db->exec('DELETE FROM sessions WHERE timestamp < ' . $db->escape(TIMESTAMP - Bl_Config::get('session.lifetime', 10800))); return true; } public static function count($timestamp = 0, $hasAnonymous = true) { global $db; if (!$hasAnonymous) { $cond = ' AND uid > 0'; } else { $cond = ''; } $result = $db->query('SELECT COUNT(0) FROM sessions WHERE timestamp > ' . $timestamp . $cond); return $result->one(); } } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Customized Session Handler can not work for PHP 5.1.6 and CentOS 5.5
Hi, All, System: CentOS 5.5; PHP version is 5.1.6. I met a strange problem associate with session_save_handler in current environment(The same code can work well in my local windows platform and ubuntu system). I just want to use a customized session save handler to be triggered, so that I can call my own logic to handling the session. The testing in local is pretty great but when migration to the VPS, it bring me the following error: Fatal error: session_start() [href='function.session-start'>function.session-start]: Failed to initialize storage module: user (path: /tmp) The default value for session save handler and session save path in php.ini are: session.save_handler = files session.save_path = "/tmp" session.name = PHPSESSID And the bottom are the code for the session handler. I first called ob_start(), and after calling session::init(), I called session_start(). Then the fatal error happen. It did not trigger any function in the "session" class. I tried change the php.ini from session.save_handler = user, but the error remains. And I found no matter what session.save_handler type is, after calling session_set_save_handler(), the session.save_handler will always automatically changed to 'user', that's why the Fatal error info shows user (path: /tmp). Can anybody help me out for such error? I was stuck by this issue for more than 2 days, but still haven't get any clue! You can view more details from stackoverflow if you want. Here is the link: http://stackoverflow.com/questions/8845924/session-set-save-handler-class-for-database-not-working session_set_save_handler('session::open', 'session::close', 'session::read', 'session::write', 'session::destroy', 'session::gc'); } public static function open($save_path, $session_name) { if (!is_dir($save_path)) { mkdir($save_path, 0777); } return true; } public static function close() { return true; } public static function read($sid) { global $db, $user; register_shutdown_function('session_write_close'); if (!isset($_COOKIE[session_name()])) { $user = anonymousUser($sid); return ''; } $result = $db->query('SELECT s.data as session_data, s.* , u.* FROM users u INNER JOIN sessions s ON u.uid = s.uid WHERE s.sid = "' . $db->escape($sid) . '" AND timestamp >= ' . $db->escape(TIMESTAMP - Bl_Config::get('session.lifetime', 10800))); $user = $result->row(); if ($user) { $data = $user->session_data; unset($user->passwd, $user->session_data); if ($user->uid > 0 && $user->status == 1) { $userInstance = User_Model::getInstance(); $user->roles = $userInstance->getUserRoles($user->uid); $user->roles[] = User_Model::ROLE_AUTHENTICATED_USER; $user->permissions = array(); $user->data = (isset($user->data) && $user->data) ? unserialize($user->data) : array(); foreach ($user->roles as $rid) { $user->permissions = array_merge($user->permissions, $userInstance->getRolePermissions($rid)); } $user->permissions = array_unique($user->permissions); } else { $user = anonymousUser($sid); } return $data; } else { $user = anonymousUser($sid); return ''; } } public static function write($sid, $data) { global $db, $user; if (!isset($user) || ($user->uid == 0 && empty($_COOKIE[session_name()]) && empty($data))) { return true; } $uri = '/' . Bl_Core::getUri(); $db->exec('UPDATE sessions SET uid = ' . $db->escape($user->uid) . ', ip = "' . $db->escape(ipAddress()) . '", uri = "' . $db->escape($uri) . '", data = "' . $db->escape($data) . '", timestamp = ' . $db->escape(TIMESTAMP) . ' WHERE sid = "' . $db->escape($sid) . '"'); if (!$db->affected()) { $db->exec('INSERT IGNORE INTO sessions (sid, uid, ip, uri, data, timestamp) VALUES ("' . $db->escape($sid) . '", ' . $db->escape($user->uid) . ', "' . $db->escape(ipAddress()) . '", "' . $db->escape($uri) . '", "' . $db->escape($data) . '", ' . $db->escape(TIMESTAMP) . ')'); } return true; } public static function destroy($sid) { global $db; $db->exec('DELETE FROM sessions WHERE sid = "' . $db->escape($sid) .. '"'); return true; } public static function gc($lifetime) { global $db; $db->exec('DELETE FROM sessions WHERE timestamp < ' . $db->escape(TIMESTAMP - Bl_Config::get('session.lifetime', 10800))); return true; } public static function count($timestamp = 0, $hasAnonymous = true) { global $db; if (!$hasAnonymous) { $cond = ' AND uid > 0'; } else { $cond = ''; } $result = $db->query('SELECT COUNT(0) FROM sessions WHERE timestamp > ' . $timestamp . $cond); return $result->one(); } } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Customized Session Handler can not work for PHP 5.1.6 and CentOS 5.5
Hi, All, I can't see the post I sent several hours ago, if repeated, please reply to this one. Thanks! System: CentOS 5.5; PHP version is 5.1.6. I met a strange problem associate with session_save_handler in current environment(The same code can work well in my local windows platform and ubuntu system). I just want to use a customized session save handler to be triggered, so that I can call my own logic to handling the session. The testing in local is pretty great but when migration to the VPS, it bring me the following error: Fatal error: session_start() [href='function.session-start'>function.session-start]: Failed to initialize storage module: user (path: /tmp) The default value for session save handler and session save path in php.ini are: session.save_handler = files session.save_path = "/tmp" session.name = PHPSESSID And the bottom are the code for the session handler. I first called ob_start(), and after calling session::init(), I called session_start(). Then the fatal error happen. It did not trigger any function in the "session" class. I tried change the php.ini from session.save_handler = user, but the error remains. And I found no matter what session.save_handler type is, after calling session_set_save_handler(), the session.save_handler will always automatically changed to 'user', that's why the Fatal error info shows user (path: /tmp). Can anybody help me out for such error? I was stuck by this issue for more than 2 days, but still haven't get any clue! You can view more details from stackoverflow if you want. Here is the link: http://stackoverflow.com/questions/8845924/session-set-save-handler-class-for-database-not-working -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php