betohairmass Posted August 5, 2010 Share Posted August 5, 2010 Hi,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.thanks Link to comment Share on other sites More sharing options...
betohairmass Posted August 6, 2010 Author Share Posted August 6, 2010 is this possible at all? Or do I have to let analytics to track everyone? Link to comment Share on other sites More sharing options...
codegrunt Posted May 5, 2011 Share Posted May 5, 2011 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. /admin/isLogged.php <?php // display logged in status define('PS_ADMIN_DIR', getcwd()); include(PS_ADMIN_DIR.'/../config/config.inc.php'); /* Header can't be included, so cookie must be created here */ $cookie = new Cookie('psAdmin'); if ($cookie->id_employee) echo 1; else 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:http://api.jquery.com/jQuery.get/Cheers Link to comment Share on other sites More sharing options...
Prestapepe Posted February 21, 2012 Share Posted February 21, 2012 Thanks, you are the man! I manage to do that jquery thingy... (I still can belive why this control cant be done in the fo by standard, so usefull!!) Link to comment Share on other sites More sharing options...
ghazaal Posted April 16, 2019 Share Posted April 16, 2019 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` } 2 Link to comment Share on other sites More sharing options...
MrManchot Posted August 14, 2023 Share Posted August 14, 2023 The simplest solution for me : $admin_cookie = new Cookie('psAdmin'); $is_bo_connected = $admin_cookie->id_employee !== false; Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now