EllisLab text mark
Advanced Search
     
How to check if someone is logged in?
Posted: 17 April 2009 08:39 PM
Avatar
Joined: 2006-04-15
12649 posts

Hopefully a quick one this?

I’m just wondering in an extension how do you check to see if a person is logged in or not? I was thinking of checking the member_id using the $SESS->userdata[‘member_id’] with it returning 0 but unfortunately that would be 0 for the Super Admin so that is out.

Is there any built in way to check to see if a user is logged in or not. I’m not talking about {if logged_in} though as this is for an extension.

Thanks for any help on this.

Best wishes,

Mark

 Signature 

Shopping Cart Plugin | Full List Of Add-Ons | About Me
——————————————————————————————
2.x Bug Tracker | Upgrade Errors

 
Posted: 18 April 2009 08:43 AM   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2002-06-03
6512 posts

member_id should never be zero for a member, the autoincrement field starts at 1.  Checking for a member_id of 0 would be fine, and is in fact how the Template class parses {if logged_in} {if logged_out} conditionals.

 Signature 
 
Posted: 18 April 2009 09:04 AM   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2006-04-15
12649 posts

Hi Derek,

Oops sorry I meant to post back to say what a numb-skull I am!! Pretty much after I’d posted that I saw that the admin user is never 0! For some reason I had it stuck in my head that it was but I even had the exp_members table open in front of me whilst I was writing it and had the Super Admin number staring me in the face!!!

Don’t I feel silly now. Funny how something that is wrong can stick in your head. Well that one’s well and truly unstuck now.

Thanks for the post and sorry not to have posted back sooner to have saved you 217 finger movements!! grin

Thanks for the extra information though. Now to get on with the extension I’m trying to make.

Hope you’re having a great weekend. I’m currently writing a piano piece which I’ll probably turn into a song with the help of my fantastic singer of a Wife whilst writing the extension. Who says men can’t multi-task!! grin

Best wishes,

Mark

 Signature 

Shopping Cart Plugin | Full List Of Add-Ons | About Me
——————————————————————————————
2.x Bug Tracker | Upgrade Errors

 
Posted: 19 April 2009 10:17 AM   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2002-06-03
6512 posts

No problem, Mark.

 Signature 
 
Posted: 19 April 2009 10:19 AM   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2006-04-15
12649 posts

You may have already seen it but the extension is now online - Unregistered Comment. Hopefully I’ve not done anything silly with it, just wanted it to be a nice quick way to do what it does and hopefully it is all safe in what I have done?

There’s also a related Feature Request that goes with this one wink

Had a few people Tweeting about it and contacting me about it being a feature request so thought I’d go ahead and ask even though it was more their idea than mine wink

Best wishes,

Mark

 Signature 

Shopping Cart Plugin | Full List Of Add-Ons | About Me
——————————————————————————————
2.x Bug Tracker | Upgrade Errors