views:

2483

answers:

4

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?

+6  A: 

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
I've now set it to / and that works perfectly! Thanks.
Martijn Heemels
A: 

I have the same problem, i want to access to the magento's customer session, from another php application placed in the same server.

I have copy and paste the test.php code and all i get is false when the test.php dump the variable and including exceptions

Exception: Warning: include(DoppelGangerView.php) ......

I have already change the cookies path, i have set it to / and i get:

Exception: Warning: include(DoppelGangerView.php) ......

bernal
Welcome to SO, Bernal. Your post is not an answer to my question. You should have created a question of your own though. A properly written question would lead to more answers than you got now.
Martijn Heemels
A: 

"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
Roland, thanks for trying to help bernal, but his question shouldn't have been here in the first place.
Martijn Heemels
A: 

Oh wow, the Cookie answer is +100 in my book (I'm too newb to vote it up).

I have been fighting this issue for days - Magento presents many odd ball issues when its installed in a subdirectory.

Thank you sooo much!

-Ed.

Edison Software