I am building a small web services code to where I need to have Magento customer login.

But I am not able to create the session. If I create the session from core/session it remains same for all users.

Question 1: Where are the sessions stored in the database?

Question 2: How to create a customer session (customer/session) and then fetch that on different locations with the same session ID??

1 Answer 1


Include Mage.php from Magento in your external application

// Include Magento application
require_once ( "/your-magento-directory/app/Mage.php" );
// Initialize Magento

You have two options then, for the session name, "frontend" for frontend session or "adminhtml" for admin session:

Mage::getSingleton("core/session", array("name" => "frontend"));
$session = Mage::getSingleton("customer/session");

This will get the session of the current logged in user.

And this will login to Magento from outside:

$session = Mage::getSingleton('customer/session', array('name' => 'frontend'));
$session->login($row['mail'], $row['field_magentopass_value']);

$row['mail'] is the email with user is registered $row['field_magentopass_value'] is the password

Source: http://louisjohn.wordpress.com/category/magento/magento-functions-outside-magento-folder/

  • To Login $session->login($row['mail'], row['field_magentopass_value']); what is the values to pass: $row['mail'] is replaced by customers mail id but what about the another one? May 30, 2013 at 11:01
  • sorry for not mentioning it earlier. edited the answer. please check
    – zamil
    May 30, 2013 at 11:26
  • Sir I am getting 500 error when I am using this. I tried password and also hash value from db also. But 500 error is coming up May 30, 2013 at 11:29
  • @HarsimranSingh:I don't know why it throws 500 error. but make sure the paths are correct.I use this to login from drupal 7 to magento 1.7 CE.I verified it now once again
    – zamil
    May 30, 2013 at 11:51
  • Sorry was a minor mistake of mine.. But Logged n how to check whether the logged in user is same? like session id or email to check with? May 30, 2013 at 11:56

Not the answer you're looking for? Browse other questions tagged or ask your own question.