I am trying to integrate an external site with magento, so that when a user logs into site A, magentos session cookie gets set.
Currently I am doing this:
<?php $email = $_POST["email"]; $password = $_POST["password"]; // not the same as magento password //Validation.... sets that user is logged in in $_SESSION session_start(); //login writes to $_SESSION $success = login($username, $password); if(!$success)die("Wrong credentials"); require_once("/path/to/mysite/magento/app/Mage.php"); Mage::app("default"); Mage::getSingleton('core/session', array('name' => 'frontend')); $customer = Mage::getModel("customer/customer"); $customer->setWebsiteId(Mage::app()->getWebsite()->getId()); $customer->loadByEmail($email); $session = Mage::getSingleton("customer/session"); $session->loginById($customer->getId()); $session->setCustomerAsLoggedIn($customer); //User is now logged in, redirect somewhere else header("Location: home.php");
the problem is if I write to the session before magento starts it's magic, magento won't write to its cookie, and if I start magentos session before validation I can no longer write to $_SESSION and have it persist to the next (non-magento) page.
So, is there any way I can log a user into magento from outside magento, and not ruin my session?