Recent Topics

1 Dec 08, 2006 04:36    

How do check if Admin is logged-in?

I want to display a count on my page to show the number of visitors online - 1 if the admin is login.

Thanks.

2 Dec 08, 2006 06:12

go to your backoffice and users, then click the admin account, then uncheck 'show online' then click save.

3 Dec 08, 2006 06:28

Thanks, but that is not what I want to do. I have a variable $user (integer) in File called users.php (it's an add-on) that I want to sheck if Admin is logged-in then echo $user should be $user -1;

4 Dec 08, 2006 06:42

Ah ok, try;
array_keys($Sessions->_registered_Users); should give you a array of all the user id's that are logged in at the time. You should be able to figure the rest out.

5 Dec 08, 2006 06:52

Thanks again, but from the backoffice I know the Admin ID. Can you please tell the variable name that test that ID.

6 Dec 08, 2006 08:18

yeh so;
$logged_in_users = array_keys($Sessions->_registered_Users);
in_array($admin_id, $logged_in_users);

should return whether the admin is logged in or not.

8 Dec 08, 2006 16:51

kskhater since you're running 0.9.2 I'm not sure balupton's info will work. He's a 1.* guy is the thing. If it doesn't get you where you want to be try this:

if( is_logged_in() ) { // gotta be true since you're in the back office?
if( $current_User->('ID') == 1 ) { // this is The Admin ID
$whatever_you_need = true;
}
}

Actually it's been so long I'm not sure if you use $current_User->('ID') or $current_User->get('ID') but I think it's the first. The second way (with a get) will probably display the ID on the page.

9 Dec 08, 2006 17:15

Many Thanks, you are right, the previous metod did not work. yYour method worked.

10 Feb 10, 2007 04:30

balupton,

I'm using 1.9.2 now and have tried to use your code like this:


<? $logged_in_users = array_keys($Sessions->_registered_Users);
  if( in_array($admin_id, $logged_in_users) { 
	$user = $user -1;
	} ?>

but I get the following errors:

Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/alkha4/public_html/blog/addOns/visitors/users.php on line 43

Notice: Undefined variable: admin_id in /home/alkha4/public_html/blog/addOns/visitors/users.php on line 44

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/alkha4/public_html/blog/addOns/visitors/users.php on line 44


Form is loading...