例如,我需要从此会话中检索值。我应该怎么做 ?确切地说,我需要获得“ customer_log_id ”。
> Array (
> [core] => Array
> (
> [_session_validator_data] => Array
> (
> [remote_addr] => 127.0.0.1
> [http_via] =>
> [http_x_forwarded_for] =>
> [http_user_agent] => Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5
> )
>
> [session_hosts] => Array
> (
> [127.0.0.1] => 1
> )
>
> [messages] => Mage_Core_Model_Message_Collection
> Object
> (
> [_messages:protected] => Array
> (
> )
>
> [_lastAddedMessage:protected] =>
> )
>
> [visitor_data] => Array
> (
> [] =>
> [server_addr] => 2130706433
> [remote_addr] => 2130706433
> [http_secure] =>
> [http_host] => 127.0.0.1
> [http_user_agent] => Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5
> [http_accept_language] =>
> en-us,en;q=0.5
> [http_accept_charset] =>
> ISO-8859-1,utf-8;q=0.7,*;q=0.7
> [request_uri] => /currentproject/magento/index.php/customer/account/
> [session_id] => 34989ee1673caefec0d887dd41198587
> [http_referer] => http://127.0.0.1/currentproject/magento/index.php/customer/account/login/
> [first_visit_at] => 2009-12-04 11:20:24
> [is_new_visitor] =>
> [last_visit_at] => 2009-12-04 11:32:26
> [visitor_id] => 208
> [last_url_id] => 1399
> [catalog_compare_items_count] => 0
> [do_customer_login] =>
> [customer_id] => 1
> [customer_log_id] => 8
> )
>
> [last_url] => http://127.0.0.1/currentproject/magento/index.php/customer/account/index/
> [just_voted_poll] =>
> )
>
> [_cookie_revalidate] => 1259926524
> [customer_base] => Array
> (
> [_session_validator_data] => Array
> (
> [remote_addr] => 127.0.0.1
> [http_via] =>
> [http_x_forwarded_for] =>
> [http_user_agent] => Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5
> )
>
> [session_hosts] => Array
> (
> [127.0.0.1] => 1
> )
>
> [messages] => Mage_Core_Model_Message_Collection
> Object
> (
> [_messages:protected] => Array
> (
> )
>
> [_lastAddedMessage:protected] =>
> )
>
> [id] => 1
> )
>
> [checkout] => Array
> (
> [_session_validator_data] => Array
> (
> [remote_addr] => 127.0.0.1
> [http_via] =>
> [http_x_forwarded_for] =>
> [http_user_agent] => Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5
> )
>
> [session_hosts] => Array
> (
> [127.0.0.1] => 1
> )
>
> [quote_id_1] =>
> )
>
> [catalog] => Array
> (
> [_session_validator_data] => Array
> (
> [remote_addr] => 127.0.0.1
> [http_via] =>
> [http_x_forwarded_for] =>
> [http_user_agent] => Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5
> )
>
> [session_hosts] => Array
> (
> [127.0.0.1] => 1
> )
>
> [messages] => Mage_Core_Model_Message_Collection
> Object
> (
> [_messages:protected] => Array
> (
> )
>
> [_lastAddedMessage:protected] =>
> )
>
> )
>
> [newsletter] => Array
> (
> [_session_validator_data] => Array
> (
> [remote_addr] => 127.0.0.1
> [http_via] =>
> [http_x_forwarded_for] =>
> [http_user_agent] => Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5
> )
>
> [session_hosts] => Array
> (
> [127.0.0.1] => 1
> )
>
> )
>
> )
答案 0 :(得分:1)
$a['core']['visitor_data']['customer_log_id']
答案 1 :(得分:1)
您似乎正在尝试从$_SESSION
数组中检索信息。有两种方法可以做到这一点。正如另一张海报建议的那样,你可以简单地将它从$_SESSION
超级全球中删除:
$logId = $_SESSION['core']['visitor_data']['customer_log_id'];
然而,这是一个避免Magento框架的黑客攻击。更好的选择(从“正确性”的角度来看)是使用Magento的会话管理。所以,相反,我们有:
// we could also skip a step and just use Mage::getSingleton("core/session")->getVisitorData(),
// but I wanted to add the datatypes for your reference
$session = Mage::getSingleton("core/session"); // Mage_Core_Model_Session
$customerData = $session->getVisitorData(); // array
$logId = $customerData['customer_log_id']; // int
希望有所帮助!