Jump to content

check if admin is logged in front office


Recommended Posts


I want to check if the admin is logged in the front office.

in the init script of the front office I have added

$cookies = new Cookie('psAdmin');
$cookie->id_empl = $cookies->id_employee;

do that i can ceck if id_empl has a value. But this value is not set.

I want to know if the admin is logged in so that I can include google analytics or not. I do not want to track click from my employees when they click on add to carts or navigate round the site as this will distort the tracking numbers.

Doe anyone have any advice on this.


Share this post

Link to post
Share on other sites

  • 8 months later...

I'm bumping this old thread as it is what comes up first when doing a Google search for "prestashop test if logged in as admin".

As far as I can tell so far, it is not possible to directly test whether a user is logged in as an administrator from the front office PHP files ("order.php", etc.). The problem is that the admin cookie has its path set to the admin directory which means front end pages cannot see it. This has the benefit of letting you be logged in as a customer and as admin (for testing) but means that you can't test for employees on the front office.

In your case however you are just wanting to disable some Javascript if the user is not logged in. What you could do is to setup a very simple script in the admin directory that tests whether the admin cookie is set and spits out a status value.



// display logged in status
define('PS_ADMIN_DIR', getcwd());


/* Header can't be included, so cookie must be created here */
$cookie = new Cookie('psAdmin');
if ($cookie->id_employee)
   echo 1;
       echo 0;

Then, in your front office templates add some Javascript to call this file and use the result to control whether you enable analytics or not. JQuery can likely make this less work:



Share this post

Link to post
Share on other sites

  • 9 months later...
  • 7 years later...

in my case this code work 

  $cookie2 = Context::getContext()->cookie;
        $cookie = new Cookie('psAdmin', '', (int)Configuration::get('PS_COOKIE_LIFETIME_BO'));
        $employee = new Employee((int)$cookie->id_employee);

        if (Validate::isLoadedObject($employee) && $employee->checkPassword((int)$cookie->id_employee, $cookie->passwd)
            && (!isset($cookie->remote_addr) || $cookie->remote_addr == ip2long(Tools::getRemoteAddr()) || !Configuration::get('PS_COOKIE_CHECKIP')))
            echo 'you login';

        if ($cookie2->getAll()['logged']) {
           echo 'you login`


  • Like 2

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More