harlandraka94 Posted August 5, 2016 Share Posted August 5, 2016 (edited) I have an app running in the same domain as my prestashop shop. I would like to do something like a single sign-on: you log into prestashop, the app knows you are logged in and doesn't ask for login again. I saw this code in another thread: require_once(dirname(__FILE__).'/../config/config.inc.php'); // points to the correct file require_once(dirname(__FILE__).'/../config/settings.inc.php'); // points to the correct file $context = Context::getContext(); if (isset($context->employee) && $context->employee->id > 0) { $id_employee = $context->employee->id; echo "ID Employee: $id_employee"; } else { echo "No employee logged in."; } die(); It doesn't work, it outputs "No employee logged in.", no matter if I'm logged in or not (I'm an admin). If I print_r the context object, employee comes blank, even if I'm logged in. Is it possible to check if an employee is logged in outside prestashop? How? Thank you Edited August 5, 2016 by harlandraka94 (see edit history) 1 Link to comment Share on other sites More sharing options...
Rolige Posted August 5, 2016 Share Posted August 5, 2016 The best way is enter in the ecosystem of PrestaShop through a file, controller, module, etc, etc. This is an example with a simple file in the root.... Create a file in the root directory of the shop: cookie_access.php Add this code inside the file: <?php require_once dirname(__FILE__).'/config/config.inc.php'; $cookie = new Cookie('psAdmin', '', (int)Configuration::get('PS_COOKIE_LIFETIME_BO')); if (isset($cookie->id_employee) && $cookie->id_employee) { echo 'ID Employee: '.$cookie->id_employee; } else { echo 'No employee logged in.'; } Now you can verify if an employee is logged in the Back Office by calling this file: http://domain.com/cookie_access.php Hope this help you! 3 Link to comment Share on other sites More sharing options...
harlandraka94 Posted August 6, 2016 Author Share Posted August 6, 2016 The best way is enter in the ecosystem of PrestaShop through a file, controller, module, etc, etc. This is an example with a simple file in the root.... Create a file in the root directory of the shop: cookie_access.php Add this code inside the file: <?php require_once dirname(__FILE__).'/config/config.inc.php'; $cookie = new Cookie('psAdmin', '', (int)Configuration::get('PS_COOKIE_LIFETIME_BO')); if (isset($cookie->id_employee) && $cookie->id_employee) { echo 'ID Employee: '.$cookie->id_employee; } else { echo 'No employee logged in.'; } Now you can verify if an employee is logged in the Back Office by calling this file: http://domain.com/cookie_access.php Hope this help you! It seems to work, thank you! Link to comment Share on other sites More sharing options...
gfstudio Posted May 14, 2018 Share Posted May 14, 2018 This code seems to be correctly working on firefox. On chrome the id_employee's not being retrieved. Cookie Object ( [_content:protected] => Array ( [date_add] => 2018-05-14 14:00:30 [id_lang] => 1 [detect_language] => 1 [employee_form_lang] => 1 [id_employee] => 181 [email] => [email protected] [profile] => 1 [passwd] => b3db667d1eb09459668b87f7eda24f8d [remote_addr] => 1348153989 [shopContext] => s-1 [checksum] => 3082462495 ) Cookie Object ( [_content:protected] => Array ( [date_add] => 2018-05-14 14:10:04 [id_lang] => 1 [detect_language] => 1 ) First one is firefox and second one is chrome ... any suggestions ? Link to comment Share on other sites More sharing options...
ZiedDams Posted January 13, 2022 Share Posted January 13, 2022 On 8/5/2016 at 9:13 PM, Rolige said: The best way is enter in the ecosystem of PrestaShop through a file, controller, module, etc, etc. This is an example with a simple file in the root.... Create a file in the root directory of the shop: cookie_access.php Add this code inside the file: <?php require_once dirname(__FILE__).'/config/config.inc.php'; $cookie = new Cookie('psAdmin', '', (int)Configuration::get('PS_COOKIE_LIFETIME_BO')); if (isset($cookie->id_employee) && $cookie->id_employee) { echo 'ID Employee: '.$cookie->id_employee; } else { echo 'No employee logged in.'; } Now you can verify if an employee is logged in the Back Office by calling this file: http://domain.com/cookie_access.php Hope this help you! thank you, but how to call this file inside my module main php file ? 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