how to know whether a user is logged in or not

Re: how to know whether a user is logged in or not

by Davo Smith -
Number of replies: 0
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

You are right that this is an old thread (which probably should be left in peace). But I'll respond to point out that you've not answered the original question - which was about showing the logged-in status of other users.

For the current user, you should use isloggedin() (possibly combined with isguestuser(), to check they are a real user). It happens that isloggedin() just calls !empty($USER->id), so your method would probably work anyway (but possibly with a debugging warning, if the $USER object had no 'id' field defined).