I can't get customer session in my magento external site (same domain)

I can't get customer session in my magento external site (same domain)

October 16, 2026 · Illustrated author avatarBy Stefan Bogdanescu
I can't get customer session in my magento external site (same domain)

Accessing Magento Customer Session in an External Folder: A Comprehensive Guide

Hello developers! Today, we’re going to tackle a common challenge faced by many who are extending the functionality of their Magento stores using external folders, such as magento/myApp. The task? Retrieving the customer session data from the main Magento site into our external folder. Let’s dive right in!

Understanding the Challenge: Same Domain, Different Scope

Before we proceed with any solutions, let’s understand why this is a tricky issue. When you have an external folder (like magento/myApp) under the same domain as your Magento installation but outside of its core structure, the session data is not automatically shared. This is because Magento treats these folders as separate areas.

The Incorrect Approach: Using Mage::getSingleton()

You’ve attempted to use Mage::getSingleton("core/session", array("name"=>"frontend")); and Mage::getSingleton("customer/session", array("name"=>"frontend"));. While this approach might work within the main Magento folder, it fails in an external one because of the session scope issue we discussed earlier.

The Correct Approach: Sharing Session Data

To share session data between your Magento core and the external folder, you’ll need to configure both areas to use the same session storage. Here’s how:

  1. Configure Magento Core: In your main Magento configuration file (usually app/etc/local.xml), ensure that the session save path is set correctly for the frontend. It should look something like this:

    <session>
        ...
        <save><![CDATA[files]]></save>
        <serialize><![CDATA[1]]></serialize>
        <gc<lifeTime><![CDATA[120]]></lifeTime>
        <autoStart><![CDATA[0]]></autoStart>
    </session>
    

    The <save> node should be set to files if you want to use the file system for session storage. This is the most common setting.

  2. Configure External Folder: In your external folder, ensure that your application also uses the same session storage configuration as Magento core. If you’re using PHP’s built-in session handling (which is typical), you’ll need to set the session.save_path in your .htaccess or an include file like this:

    session_save_path('/path/to/your/session/directory');
    

Make sure that the session directory path matches Magento core’s session save path.

The Final Touch: Accessing the Session Data

Once you’ve configured both areas to use the same session storage, accessing the customer session data in your external folder is straightforward:

  1. Call session_start() at the beginning of your script.

  2. Retrieve the customer data using PHP’s built-in $_SESSION superglobal.

    if(isset($_SESSION['customer'])) {
        // Customer is logged in; do something
    } else {
        // Customer is not logged in; do something else
    }
    
  3. You can then use $_SESSION[‘customer’] to access various customer attributes like name, email, etc.

Conclusion: Unlocking the Potential of External Folders

As you’ve seen, accessing Magento’s customer session data from an external folder on the same domain requires a thorough understanding of how session management works in PHP and Magento. By correctly configuring both areas to use the same session storage, you can unlock the full potential of your external folders.

Remember, this approach assumes that you’re working within the same domain as your main Magento installation. If you’re on a subdomain or different domain altogether, additional configuration will be required to handle cross-domain session sharing.

I hope this guide has provided you with the clarity and best practices needed to tackle this common challenge. If you found this article helpful, please consider exploring our other developer-focused resources at Laravel Company. Happy coding!

Word count: 450 (excluding headings and code samples)

Configuration Customers Errors

Our network