2

Hereby, I working in PHP Outside Magento Folder.Here I need to get Session values like Customer ID into Outside Magento.Here I working this sample code in outside Magento.

<?php
// Your Magento Mage.php
// Mage Enabler WordPress plugin users may
// skip line numbers 5, 6 and 7
require_once ("/var/www/magento_pack/app/Mage.php");
umask(0);
Mage::app("default");
#Mage::setIsDeveloperMode(true);
#ini_set('display_errors', 1);
umask(0);
Mage::app()->loadArea('frontend');

$layout = Mage::getSingleton('core/layout');

//load default xml layout handle and generate blocks
$layout->getUpdate()->load('default');
$layout->generateXml()->generateBlocks();

//get the loaded head and header blocks and output
$headBlock = $layout->getBlock('head');
$headerBlock = $layout->getBlock('header');
$footerBlock = $layout->getBlock('footer');
// echo $headBlock->toHtml() . $headerBlock->toHtml().$footerBlock->toHtml();
Mage::getSingleton('core/session', array('name' => 'frontend'));
if(Mage::getSingleton('customer/session')->isLoggedIn())
  echo Mage::getSingleton('customer/session')->getId();
else
  echo 'Not logged in';
  exit;

But Doesnt show proper customers details.How to achieve outside magento session value exactly customer details.Kindly Advise me...

7

Try moving your core session initialization above the layout calls:

require_once ("/var/www/magento_pack/app/Mage.php");
umask(0);
Mage::app("default");
#Mage::setIsDeveloperMode(true);
#ini_set('display_errors', 1);
umask(0);
Mage::app()->loadArea('frontend');
Mage::getSingleton('core/session', array('name' => 'frontend'));

$layout = Mage::getSingleton('core/layout');

//load default xml layout handle and generate blocks
$layout->getUpdate()->load('default');
$layout->generateXml()->generateBlocks();

//get the loaded head and header blocks and output
$headBlock = $layout->getBlock('head');
$headerBlock = $layout->getBlock('header');
$footerBlock = $layout->getBlock('footer');
// echo $headBlock->toHtml() . $headerBlock->toHtml().$footerBlock->toHtml();
if(Mage::getSingleton('customer/session')->isLoggedIn())
  echo Mage::getSingleton('customer/session')->getId();
else
  echo 'Not logged in';
exit;
  • Hi @Laura..I have already this above code in my sample Script.Kindly go through it..Eagerly wait for your valuable answer.. – VIVEK-MDU Feb 20 '15 at 4:52
  • Did you move the session call up and it's still not working? – Laura Feb 20 '15 at 14:50
  • Yes @Laura..Still not working fine.I tried many ways to reach it but yet not get back proper result.Kindly advise me.. – VIVEK-MDU Feb 21 '15 at 6:03
  • I updated the code block in the answer. This is working for me. One question: are you sure the user is actually logged into the frontend of the Magento site when you're running this? – Laura Feb 23 '15 at 14:49
  • Yes @Laura..absolutely correct..i need to get user detail outside magento. I have connect with core php website i need to merge log-in credential.Let me check it out and get back to you.. – VIVEK-MDU Feb 24 '15 at 4:25
2

There shouldn't be any need to do all this, something like:

require 'Mage.php';
Mage::app();
Mage::getSingleton('customer/session')->getCustomerId()

should do the job.

This only works, if you are calling this script under the same domain (read as: cookie domain) as your real magento. If you can't read the session id from the cookie, because you are under another domain, you are lost.

1
require_once 'app/Mage.php';


umask(0);

Mage::app('default');

Mage::getSingleton('core/session', array('name' => 'frontend'));

$sessionCustomer = Mage::getSingleton("customer/session");

if($sessionCustomer->isLoggedIn()) {
  echo $customerId = $sessionCustomer->getId();
} else {
   echo "Not Logged";
}
1

Try this code.

<?php
require_once ('app/Mage.php');
Mage::app();
// Define the path to the root of Magento installation.
define('ROOT', Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB));
$coreSession = Mage::getSingleton('core/session', array('name' => 'frontend'));
$customerSession = Mage::getSingleton("customer/session");
if($customerSession->isLoggedIn()) {
    echo "Customer is logged in";}
else{
    echo "Customer is not logged in";
}
?>
0
Mage::getSingleton('core/session', array('name' => 'frontend'));

$cusData = Mage::getSingleton('checkout/session')->getQuote();
$customerId = $cusData->getCustomer()->getid();

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.