There are many snippets available to get customer login status in a script. I'm using this:
[root]/tools/testlogin.php
require_once ('../app/Mage.php');
umask(0);
Mage::app();
Mage::getSingleton('core/session', array('name'=>'frontend'));
if ($session = Mage::getSingleton('customer/session', array('name'=>'frontend'))) {
if ($session->isLoggedIn()) {
echo 'logged in';
} else {
echo 'not logged in!';
}
} else {
// not even a session.
echo 'not logged in';
}
It worked a couple of times earlier, but no matter what I do, I don't get the 'logged in' message anymore. I've logged out & back in at the shop. After logout from the shop, I also noticed the 'not logged in' message appear.
I've tried clearing browser sessions, Magento cache etc. Didn't work.
I've tried calling Mage::app('default');
. No luck.
The only way I can make it work, 100% of the time, is by using Opera browser and putting the script not in /tools/ but in the root of the shop. For an isolated test, this is OK, but not for a complete application I'm building.
My cookie settings in Magento backoffice: (all default) Cookie path: < empty > Cookie domain: < empty >
If I specify a Cookie path: / The testlogin script doesn't even work in the root anymore.
I've also set cache headers in my script:
header("Cache-Control: no-cache, must-revalidate"); //HTTP 1.1
header("Pragma: no-cache"); //HTTP 1.0
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
I'm afraid I've run out of options. Anyone?