Jump to content

How to understand if an admin is logged in as user?


Remitur

Recommended Posts

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?  

Link to comment
Share on other sites

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']))

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated