isloggedin and isregistered
Permalink 1 user found helpful
Whats the difference between them?
if the user is logged in, then they are registered, and vice versa, right?
if the user is logged in, then they are registered, and vice versa, right?
Not necessarily. If you have a user object that is not the current user (for example, $u = User::getByID(10)), then $u->isRegistered might return true, but $u->isLoggedIn might not.
One other thing: Looks like it should be $u->checkLogin, instead of $u->isLoggedIn
but if you do $u = User::getByID(10)) then they are obviously registered....
True. But $u = new User would return false on isRegistered if the user is just a visitor (I am assuming...I haven't tested this).
Technically speaking, the way you're thinking about it they are the same, but how you apply them might be different.
Scenario: I have a members list on my site. I want to put a little green light next to each member if they are logged in (online) and a red light if they are not. In this case, I would use isLoggedIn to see if they are currently logged in to my site.
Using isRegistered wouldn't work in this scenario, because they would have to be registered to be in my member list, but they might not be logged in.
Now, someone else might be able to tell you why you should use isRegistered, but it's probably used more often to hide specific areas of the site for people who don't have accounts (although, admittedly, I supposed isLoggedIn would work here too.)
In any case, my scenario about a "Whose Online List" or "Online Now Icon" would need to use isLoggedIn
Scenario: I have a members list on my site. I want to put a little green light next to each member if they are logged in (online) and a red light if they are not. In this case, I would use isLoggedIn to see if they are currently logged in to my site.
Using isRegistered wouldn't work in this scenario, because they would have to be registered to be in my member list, but they might not be logged in.
Now, someone else might be able to tell you why you should use isRegistered, but it's probably used more often to hide specific areas of the site for people who don't have accounts (although, admittedly, I supposed isLoggedIn would work here too.)
In any case, my scenario about a "Whose Online List" or "Online Now Icon" would need to use isLoggedIn
Okay, so I looked at the actual code. They are both single-line methods...
So, in essence, if a user is logged in, they are always registered, but if a user is registered (and you are not referring to the current user) they may not necessarily be logged in.
Practical implications? Not many... :)
public static function isLoggedIn() { return $_SESSION['uID'] > 0 && $_SESSION['uName'] != ''; }
function isRegistered() { return $this->getUserID() > 0; }
So, in essence, if a user is logged in, they are always registered, but if a user is registered (and you are not referring to the current user) they may not necessarily be logged in.
Practical implications? Not many... :)
Although, I did just list a couple practical applications... hmm?
True. The question more important issue, however, is - who gets picked for best answer?
Let me state my case...Lucas has > 50k karma points. I have 14k. Come on mnkras, help a brother out...
Let me state my case...Lucas has > 50k karma points. I have 14k. Come on mnkras, help a brother out...
haha fine you get the answer ;)
i understand the use of isloggedin,
but if you are trying to get a user, then they have to be registered otherwise it returns false or null so i still don't get where isregistered would be used
i understand the use of isloggedin,
but if you are trying to get a user, then they have to be registered otherwise it returns false or null so i still don't get where isregistered would be used
You can use isRegistered() when you create your own login scripts. In this case you need to test if the user has completed the registration process (as set in the "users and groups" section of the dashboard) before you allow the user to continue through the website.
Another use could be to produce a list of all the users that have applied for access to your website, but have not completed the registration process.
isLoggedIn() is commonly used to display additional information to logged in users. I personally use it to prevent false statistic logging, when editing sites.
Hope that sheds some light
Another use could be to produce a list of all the users that have applied for access to your website, but have not completed the registration process.
isLoggedIn() is commonly used to display additional information to logged in users. I personally use it to prevent false statistic logging, when editing sites.
Hope that sheds some light