0

We have an external application which needs some functions/data from Magento for certain things. I decided to make the login utilise the magento admin accounts and roles. This works and I can login on our application, using the magento admin credentials.

Now I have the following code to check if the user is actually logged in or not:

if(!Mage::getSingleton('admin/session')->isLoggedIn())
{
    header('Location: /login.php');
}

This does the trick for the normal pages (returns 1 when logged in). However, if I call a script in the application using AJAX, when it goes over the same check, it returns nothing. I have tried to find why, but so far no success.

EDIT: I have found out that it's not the AJAX request causing it. When I call the script manually, it still returns that it's not logged in. The initial script that checks it is in the root, and the script that doesn't work is in a subfolder.

EDIT 2: I have changed it's folder and even though it goes through the exact same process, it works in the new one. /magedata/script.php has logged in false, /pages/magedata/script.php has logged in true. I am confused.

1

When not using ajax how is the page accessed?

I'd assume that the session cookie is not being passed with the ajax request therefore magento doesn't know what session belongs to you and therefore doesn't think you are logged in.

I would of commented by I don't have enough rep yet

  • The pages are all accessed the same way jusy by browser url, that includes our own classes and also loads Mage. There's nothing out of the ordinary there. On a side note, nothing means not logged in. I'll check with the cookies in a moment. – Deep Frozen Aug 14 '14 at 8:09
  • The exact same cookies are sent over with the AJAX request as well. Note: The AJAX request goes to one of our own scripts, then does the usual part that all pages do (check login, load needed classes etc), echos one string, then exits. – Deep Frozen Aug 14 '14 at 8:15

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.