Remitur Posted June 25, 2020 Share Posted June 25, 2020 Question: how is it possible, in a hook such as i.e. ClientAreaPage, understand if a user is logged in as himself, or if it's an administrator logged in as user? In .tpl it's easy, because we have two variables to check ( $adminMasqueradingAsClient and $adminLoggedIn) to check, but in PHP area? Real case: I'm working on this hook, which should force the user to a certain language, bound to the domain he's visiting, so, for english for example.com, french for example.fr, italian for example.it etc. It works, but I need to find a way to disable it if the logged-in user is an admin-logged-in-as-user: for some kind of unknown reason, it broke the magic of the function "login as user", and the admin so is redirected to ordinary login page. <?php add_hook('ClientAreaPage', 1, switch_languagehost($vars)); function switch_languagehost($vars) { $client= Menu::context('client'); if (is_null($client)) { $domain=$_SERVER['SERVER_NAME']; $language='english'; if ($domain=='example.fr' ) { $language='french'; } if(!isset($_SESSION['switch-language']) && $_SESSION['uid'] == false ) { $_SESSION['switch-language'] = true; // prevent from redirecting back again in this session } if(!isset($_SESSION['Language']) || $_SESSION['Language'] != $language) { $location = '?language='.$language; if($_SERVER['QUERY_STRING'] != '' && strpos($_SERVER['QUERY_STRING'],'?language')===0) $location .= '&'.$_SERVER['QUERY_STRING']; ob_clean(); header('location: '.$location); die(); } } } ?> Any idea? 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted June 25, 2020 Share Posted June 25, 2020 10 minutes ago, Remitur said: Any idea? if you're checking session values in the hook, you could see if 'adminid has been set... if so, they're an admin. 1 Quote Link to comment Share on other sites More sharing options...
Remitur Posted June 25, 2020 Author Share Posted June 25, 2020 27 minutes ago, brian! said: if you're checking session values in the hook, you could see if 'adminid has been set... if so, they're an admin. It works, thanks! Just changing from: if (is_null($client)) to if (is_null($client) AND is_null($_SESSION['adminid'])) 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.