I'm using Mangeto 1.9.1

I'm trying to access the magento customer session outside magento in a php file in the root folder of the magento.

Here is my code:

error_reporting(E_ALL | E_STRICT);
$mageFilename = 'app/Mage.php';
require_once $mageFilename;
$app = Mage::app('default'); 

$customer_id = Mage::getSingleton('customer/session')->getId();

$GrandTotal = Mage::getModel('sales/quote')->loadByCustomer($customer_id)->getGrandTotal();
$HalfTotal = $GrandTotal / 2;
echo "Grand: $GrandTotal<br>Half: $HalfTotal";

My magento is installed on a subdomain like beta.mymagento.com

But it seems it can not access the session. How i can fix it?

Thanks in advance!


You will need to enter in .domain.com in Magentos admin->system->configuration->web->cookie domain. This is assuming that the script is running on a different domain name that the Magento store.

If this is not the case and the script is running on the same domain, You next steps would be to check that you are logged in. Look at the cookie via developer tools in chrome web browser to ensure you have a valid cookie.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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