I have made a custom module which uses the customer session, but its strange, on live site its not returning customer data.
I have tried following methods:
$sessCustomer = Mage::getSingleton('customer/session', array('name' => 'frontend'));
echo '<pre>';print_r($sessCustomer->getCustomer()->getData()); echo '</pre>';exit;
It returns:
Array
(
[website_id] => 1
)
If I print the customer session:
Mage::getSingleton('customer/session')->getData();
This returns:
array(
[_session_validator_data] => Array
(
[remote_addr] => <MY IP>
[http_via] =>
[http_x_forwarded_for] => <MY IP>
[http_user_agent] => Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:16.0) Gecko/20100101 Firefox/16.0
)
[session_hosts] => Array
(
[bestevalue.info] => 1
)
[messages] => Mage_Core_Model_Message_Collection Object
(
[_messages:protected] => Array
(
)
[_lastAddedMessage:protected] =>
)
[id] =>
)
I am logged in, can see the customer dashboard with customer info on it but not able to use that session in my custom module.
Please guide me how to fix this.
Update:
I have checked in /app/etc/local.xml
that session type is file
<session_save><![CDATA[files]]></session_save>
So is there different method of extracting session info with PHP? What am I doing wrong?
Update 2:
i have used router as well to make pretty url
public function match(Zend_Controller_Request_Http $request)
on start of this action i placed
Mage::getSingleton('core/session', array('name' => 'frontend'));
but still not working with router without one it is working for example directly accessing the action :
site.com/module/controller/action
it works but not with router. any thoughts? thanks,
Best Answer
What is the point of the second parameter in
Mage::getSingleton()
? This info would be passed to the constructor of theMage_Customer_Model_Session
class, but this constructor does not take arguments:Replacing this by
should work.
I assume, that you added your
after this error-nous call which could have destroyed the session in your module.