I've create a login function that make the customer login by email and password and return below response

    "status": "success",
    "message": {
        "id": "1",
        "name": "username",
        "firstname": "firstname",
        "lastname": "lastname",
        "email": "[email protected]",
        "session_id": "7ead152bcd78c30b3f7415c985ab3d0b",
        "info": {
            "postcode": "1300",
            "city": "city",
            "street": "street",
            "telephone": "1234567890",
            "fax": null,
            "country": "USA",
            "region": null

So i want to get the customer data from the session id above but it's not working.

$sess = Mage::getSingleton('customer/session', array( 'value' => $sessId ));

My Questions:

1- How i can get the customer data from session id?

2- how i can logout the customer from the session id?

NB: This request from mobile app.

2 Answers 2


Get the customer data from session:

if (Mage::getSingleton('customer/session')->isLoggedIn()) {
    $customer = Mage::getSingleton('customer/session')->getCustomer();
    echo "<pre>";
    echo "</pre>";

Logout from session:

require_once 'app/Mage.php';
Mage::getSingleton("core/session", array("name" => "frontend"));
// get login customer data
if(Mage::getSingleton('customer/session')->isLoggedIn()) {
    $customerData = Mage::getSingleton('customer/session')->getCustomer();
     //echo $customerData->getId();

//For Logout Customer

$data['msg']="Logged Out Successfully";

echo $data2;

You can get the customer data from sessions with the following code but this is valid if you are using Magento 2.

Using object Manager

$om = \Magento\Framework\App\ObjectManager::getInstance();  
$customerSession = $om->get('Magento\Customer\Model\Session');  
$customerData = $customerSession->getCustomer()->getData(); //get all data of customerData
$customerData = $customerSession->getCustomer()->getId();//get id of customer

if you are using Magento 1:

 if (Mage::getModel('customer/session')->isLoggedIn()) {
    $customer = Mage::getSingleton('customer/session')->getCustomer();
    echo '<pre>';
} else {
    echo 'Not Logged in';

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.