9

Im trying to access the Magento customer session in another part of my website.

domain.com/shop/ <- Magento
domain.com/test.php

The shop itself works like a charm, however im trying to determine within test.php if a customer is logged in, so I can display his name with a link to his cart.

Contents of test.php so far:

<?php
require_once dirname(__FILE__).'/shop/app/Mage.php';
umask(0);
Mage::app('default');
Mage::getSingleton('core/session', array('name' => 'frontend'));
var_dump(Mage::getSingleton('customer/session')->isLoggedIn());
?>

I keep getting bool(false) returned. I'm logged into Magento at domain.com/shop/ so ‘true’ is expected.

Am I forgetting something?

Martijn Heemels
  • 3,529
  • 5
  • 37
  • 38
  • > "Exception: Warning: include(DoppelGangerView.php) ......" My guess would be it cannot find file DoppelGangerView.php somehow.. - Its not located in the current directory.. - Its not located within your include_path – Roland Franssen Feb 10 '10 at 17:01

3 Answers3

14

I would recommend checking the path of the cookie that Magento sets. Most likely, it is set to /shop, so the cookie will not be accessible to your file above it.

You can modify the path that Magento uses to set its cookie in the control panel under System -> Configuration -> Web (under the General heading) -> Session cookie management

jason
  • 8,918
  • 2
  • 37
  • 43
  • Why this is not working with joomla I tested it in separate page where it is working but not working with joomla always returns bool(false) – Shakti Singh Jan 14 '11 at 11:18
  • 2
    @Positive because this MAGENTO question is about MAGENTO, not joomla. – Benubird Jun 04 '13 at 16:21
  • You may want to create your own session model class as part of a custom module. That way you can store on it whatever you need, then in the other part of your website, instantiate the mage::app object and pull your session model data. Send me a message if you want more info on this – Paul Allsopp May 28 '15 at 20:57
0

The same issue was driving me mad. I worked through the following until the last item solved it:

  • Has the correct Mage store ID (current store) been set?
  • Are you using the same session path as Magento?
  • Are you using the same (sub)domain for cookie purposes?
  • Are you using HTTP or HTTPS both inside and outside Magento?

If you've checked all the above, make sure you initialize a core "frontend" session on its own first like this:

// Initialise the core "frontend" session
Mage::getModel('core/session', array('name' => 'frontend'));

Then you can access the customer/session like this:

$customer = Mage::getSingleton("customer/session", array('name' => 'frontend'))->getCustomer();
WackGet
  • 2,667
  • 3
  • 36
  • 50
0

it is under confuguration-> web on Magento ver. 1.10.1.1

Nikhil
  • 16,194
  • 20
  • 64
  • 81
vknyvz
  • 653
  • 7
  • 12