Magento: How to get visitor's cookies or sessi

2019-09-11 17:24发布

问题:

I want to log the recently viewed product for every visitor on the site. And for that the best way I believe is to log it via their cookie/session ID. How can I get the Session ID/Cookies of a visitor who is not logged in.

Thanks,

回答1:

you can get the visitor id by session

$vistitorId = Mage::getModel('core/session')->getVisitorId();


回答2:

To get Cookies

Mage::app()->getRequest()->getCookie();

To get Session Id

$session = Mage::getSingleton('customer/session', array('name' => 'frontend'));
echo $session->getId();
echo $session->getCustomerId();

FYI : There is a default magento functionality available for the recently viewed products

Please check the below url

Magento: Show Visitor's Recently Viewed Product