从会话存储文件中读取会话数据 [英] Read the session data from session storage file
问题描述
标题为PHP unserialize()
的功能所面对的问题将引发错误.
Facing problem with PHP unserialize()
function as titled it is throwing error.
unserialize() [function.unserialize]: Error at offset 0 of 1781 bytes
我还尝试了session_decode()
,它返回了bool(false)
I also tried the session_decode()
which return bool(false)
magic_quotes_gpc
是Off
.
好吧,我正在读取已序列化的文件的内容.文件内容如下所示.
Well, I am reading content of file which is serialized. File contents looks like below.
core | a:3:{s:23:"_ session_validator_data"; a:4:{s:11:"remote_addr"; s:15:"117.241.113.248"; s:8:"http_via"; s :0:"; s:20:"http_x_forwarded_for"; s:0:"; s:15:"http_user_agent"; s:90:"Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.13)Gecko/20101203 Firefox/3.6.13;} s:13:" session_hosts; a:1:{s:12:"; b:1;} s:8:"消息; O:34:" Mage_Core_Model_Message_Collection:2 :{s:12:"^ @ * ^ @ _ messages"; a:0:{} s:20:"^ @ * ^ @ _ lastAddedMessage"; N;}}客户| a:3:{s:23:"_session_validator_data; a:4:{s:11:" remote_addr; s:15:" 117.241.113.248; s:8:" http_via; s:0:"; s:20:" http_x_forwarded_for; s :0:"; s:15:"http_user_agent"; s:90:"Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.13)Gecko/20101203 Firefox/3.6.13;} s:13:" session_hosts; a:1:{s:12:"; b:1;} s:19:" wishlist_item_count; i:0;}目录| a: 3:{s:23:"_ session_validator_data"; a:4:{s:11:"remote_addr"; s:15:"117.241.113.248"; s:8:"http_via"; s:0:"; s :20:"http_x_forwarded_for"; s:0:"; s:15:"http_user_agent"; s:90:"Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.13)Gecko/20101203 Firefox/3.6.13;} s:13:" session_hosts; a:1:{s:12:"; b:1;} s:8:"消息; O:34:" Mage_Core_Model_Message_Collection:2 :{s:12:"^ @ * ^ @ _ messages"; a:0:{} s:20:"^ @ * ^ @ _ lastAddedMessage"; N;}}结帐| a:3:{s:23:"_session_validator_data; a:4:{s:11:" remote_addr; s:15:" 117.241.113.248; s:8:" http_via; s:0:"; s:20:" http_x_forwarded_for; s :0:"; s:15:"http_user_agent"; s:90:"Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.13)Gecko/20101203 Firefox/3.6.13;} s:13:" session_hosts; a:1:{s:12:"; b:1;} s:8:"消息; O:34:" Mage_Core_Model_Message_Collection:2 :{s:12:"^ @ * ^ @ _ messages"; a:0:{} s:20:"^ @ * ^ @ _ lastAddedMessage"; N;}}
core|a:3:{s:23:"_session_validator_data";a:4:{s:11:"remote_addr";s:15:"117.241.113.248";s:8:"http_via";s:0:"";s:20:"http_x_forwarded_for";s:0:"";s:15:"http_user_agent";s:90:"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13";}s:13:"session_hosts";a:1:{s:12:"";b:1;}s:8:"messages";O:34:"Mage_Core_Model_Message_Collection":2:{s:12:"^@*^@_messages";a:0:{}s:20:"^@*^@_lastAddedMessage";N;}}customer|a:3:{s:23:"_session_validator_data";a:4:{s:11:"remote_addr";s:15:"117.241.113.248";s:8:"http_via";s:0:"";s:20:"http_x_forwarded_for";s:0:"";s:15:"http_user_agent";s:90:"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13";}s:13:"session_hosts";a:1:{s:12:"";b:1;}s:19:"wishlist_item_count";i:0;}catalog|a:3:{s:23:"_session_validator_data";a:4:{s:11:"remote_addr";s:15:"117.241.113.248";s:8:"http_via";s:0:"";s:20:"http_x_forwarded_for";s:0:"";s:15:"http_user_agent";s:90:"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13";}s:13:"session_hosts";a:1:{s:12:"";b:1;}s:8:"messages";O:34:"Mage_Core_Model_Message_Collection":2:{s:12:"^@*^@_messages";a:0:{}s:20:"^@*^@_lastAddedMessage";N;}}checkout|a:3:{s:23:"_session_validator_data";a:4:{s:11:"remote_addr";s:15:"117.241.113.248";s:8:"http_via";s:0:"";s:20:"http_x_forwarded_for";s:0:"";s:15:"http_user_agent";s:90:"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13";}s:13:"session_hosts";a:1:{s:12:"";b:1;}s:8:"messages";O:34:"Mage_Core_Model_Message_Collection":2:{s:12:"^@*^@_messages";a:0:{}s:20:"^@*^@_lastAddedMessage";N;}}
我的PHP代码在下面
$file='/var/www/html/products/var/session/sess_0ehb7ek0hmunqo3kq70t0t6mb0';
$contents=file_get_contents($file);
$data = unserialize($contents);
var_dump($data);
在反序列化数据之前,我已经尝试过stripslashes()
.
不确定数据中的问题在哪里.
我无法更改将数据存储到文件中的机制,因为这是由Magento处理的,用于在文件级别管理会话.
I already tried the stripslashes()
before unserializing data.
Not sure where is the problem in data.
I can not change the mechanism of storing data in to file because this is handled by Magento for mananging session on File level.
推荐答案
如果要解码会话数据,请使用session_decode
(请参见
If you want to decode session data, use session_decode
(see the manual). unserialize
only decodes single variables, not session data.
您可以执行以下操作:
$file = '/var/www/html/products/var/session/sess_ciktos8icvk11grtpkj3u610o3';
$contents = file_get_contents($file);
session_start();
session_decode($contents);
print_r($_SESSION);
这篇关于从会话存储文件中读取会话数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!