akjackson1 posted on 2011-06-22 04:27:08 #
On a previous user class, I was able to check if a user was logged in with a function called IsUserLoggedIn(). How can I create one with this class, or accomplish the same thing?
I'm wanting to hide the login form on the home page if a user is already logged in.
Adam
The most popular forum posts:
Comments / discussions
Olaf posted on 2011-06-22 05:52:59 #
Hi,
you can do it this way:
if (!empty($_SESSION['user'])) echo 'form';
I guess this is the reason why I removed that "simple" function from the class ;)
KnightMaire posted on 2011-06-22 18:20:52 #
Olaf posted on 2011-06-22 19:02:26 #
Quote from: KnightMaire
"Or isset()"
"isset" is not a good choice because the session var could be empty too ;)
akjackson1 posted on 2011-06-22 20:43:07 #
Sweet thanks! I think I need to make a functions file and stick it in there... don't know much about OOP php, but i've learnt a lot since implementing your code!
Olaf posted on 2011-06-22 20:47:14 #
you're welcome (strange all your posts are marked as spam by akismet)
akjackson1 posted on 2011-06-22 21:28:35 #
That's odd. Akismet seems to have always worked flawlessly on my wordpress blog.
KnightMaire posted on 2011-06-22 23:06:03 #
Quote from: Olaf
""isset" is not a good choice because the session var could be empty too ;)"
It is perfectly fine in any instance. If there is an empty var, that is programming error that should be revised. set and unset is all that is needed.
But either way, its preference.
Olaf posted on 2011-06-23 04:30:03 #
@KnightMaire,
sure in many situations "isset" might be a good solution. I use "!empty" because you test a var/array/object twice. I see so often statements like:
if (isset($var) && $var != '')
This make no sense to me ;)
On the other site I have noticed very often that a session var is not destroyed after the var is "unset", in this case is "!empty" the better test situation.
KnightMaire posted on 2011-06-23 04:35:36 #
I have never had a problem with unset($_SESSION['var']) - it removes is from the array as should.
but i see your point with empty() vs isset() - just the way i was taught.
Are you saying:
if (isset($var) && $var != '') is the same as if(!empty($var)) ?
Olaf posted on 2011-06-23 05:50:03 #
Quote from: KnightMaire
Are you saying:
if (isset($var) && $var != '') is the same as if(!empty($var)) ?"
yes if "$var" is a text var you can use it this way.
in case of an array it's like if (is_array($arr) && count($arr) > 0) for float/int vars it's a shortcut for if (isset($var) && $var > 0) etc. (currently I'm not sure about objects)
Olaf posted on 2011-06-23 05:52:58 #
Quote from: akjackson1
"That's odd. Akismet seems to have always worked flawlessly on my wordpress blog."
Maybe it's you email address? try to post a comment on my web blog. I habe noticed if I use an older email address that most of my comments are marked as spam.
KnightMaire posted on 2011-06-23 14:53:12 #
Off topic -> How do I change my avatar LOL - i don't see an option in the edit profile.
and FYI - i get emails saying i replied to someone O.o
Olaf posted on 2011-06-23 19:13:02 #
Quote from: KnightMaire
"Off topic -> How do I change my avatar LOL - i don't see an option in the edit profile.
and FYI - i get emails saying i replied to someone O.o"
This forum is based on Wordpress (bbpress) and I'm busy to port the whole site section to something new ;)
Your avatar is actually a gravatar, check gravatar.com (some AutoMATTic service)