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??


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? – Harsimran Singh May 30 '13 at 11:01
  • sorry for not mentioning it earlier. edited the answer. please check – zamil May 30 '13 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 – Harsimran Singh May 30 '13 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 '13 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? – Harsimran Singh May 30 '13 at 11:56

protected by Community Jun 3 '16 at 7:30

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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