Magento 1.9.1

I'm using a PHP script to programatically login a customer by customer id. Below is a working cut down test script:

require '../../app/Mage.php';
// Initialize Magento

$customer = Mage::getModel('customer/customer')->setWebsiteId(Mage::app()->getStore()->getWebsiteId());
$customer->load('8'); //sample customer id
$mySession = Mage::getSingleton('customer/session');

if ($mySession->isLoggedIn()) {
    $custSessionId = $mySession->getEncryptedSessionId();
    Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getBaseUrl() . '?SID=' . $custSessionId)->sendResponse();

This basically works fine and on redirect the SID is passed and the customer is logged in.

Problem: when I enable SSL throughout the site (and change the unsecure baseurl to HTTPS) then the customer is not logged in on redirect.

Aside from this login issue, HTTPS / SSL on the site is working fine when enabled.

Any suggestions of things to try/check?

My URL / Cookie settings:

enter image description here

The server is apache with PHP 5.5.30, no Varnish etc and caching is all off.

With SSL disabled, when passed across to the site the customer is logged in and 1 cookie is set:

adminhtml (not secure)

The SID matches the cookie value. All is fine, however, the session/basket etc is then lost later on when we do go to a secure page (checkout, my account etc)

With SSL enabled for the entire site, when passed across to the site the customer is not logged in and 3 cookies are set:

_cid (secure) adminhtml (not secure) adminhtml_cid (secure)

however, none of the cookies match the SID passed across (do new ones get created?)

1 Answer 1


Looks like this worked for me: https://community.magento.com/t5/Version-Upgrades/Secure-cookie-flag/td-p/2997

Created a copy of the file in local code pool and commented out that section.

Hope this helps someone else in future.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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