Topic: Test if User is Logged In - MySQL Store (Read 946 times)
Atari ST fan
Posts: 8
52 credits Members referred : 0
« on: Oct 26, 2006, 08:08:41 AM »
Hi there,
Back once again. Having fun putting all this to work (formatting pages, testing, and such).
One difficulty I'm having though, is user login detection. I know I can test if a user is logged in if they have the "remember me" checkbox checked, 'cause you can test for the $_SESSION['user'] cookie. But if they don't have that checked, then its just a normal session cookie, correct? I opted to use the MySQL session storing feature, which I'm guessing should make it possible to check if a user is logged in or not. But I just don't know enough about sessions and such.
Any thoughts?
btw, I also upgraded my class file to 1.93. Thanks for that
Keith D Commiskey <snipped />
« Last Edit: Oct 26, 2006, 09:27:58 AM by olaf »
Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6357
38966 credits Members referred : 374
It's time to use PHP5!
« Reply #1 on: Oct 26, 2006, 09:26:35 AM »
Hello,
first don't place links into your posts if they are not related to the thread (the signature is the only place)
the $_SESSION['user'] is not a cookie! if you use the "remember me" option a cookie is created to remember the users login to autofill the login form (for example)
to test if the user is logged in or to protect pages check the example file "test_access_level.php" or "example.php"
Atari ST fan
Posts: 8
52 credits Members referred : 0
« Reply #3 on: Oct 26, 2006, 09:59:59 AM »
Sorry for the link. Didn't see it was in my sig in the preview.
I've scoured the examples and docs, and can't find a clear concise way to check for if they're logged in. And that link you provided is where I found the "!empty($_SESSION['user']", which appears (at least for my use) to only successfully tell if the user signed in with the remember me checked. Otherwise, it doesn't seem to acknowledge it. I've tried, and tried it; in and out, in and out.
Using the test to check for access level is great if they are logged in, otherwise it gives me an error about making a call to an object that doesn't exist or something. You see, I'd like to know if they're logged in on pages that aren't being protected ('cause the pages that are protected, I know will redirect if they're not logged in).
So in checking all the files, I just figured there has to be a way to test if they're logged in (via the mysql session value or something). I was able to see that the mysql value is removed when they log out. And, as I mentioned, it does work fine if the remember me box is checked. Just not if its not.
Sorry for not being able to figure it out, and being confused on it. Perhaps I've just tweaked it too much (but not the class, I leave that alone so I can just drop a new one in when you upgrade next).
Maybe I can query the session (cookie? - PHPSESSID) with the mysql session table, and if its in there, then they're logged in? Or maybe I'm just missing something really obvious...
Thanks!
Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6357
38966 credits Members referred : 374
It's time to use PHP5!
« Reply #4 on: Oct 26, 2006, 10:12:43 AM »
forget the cookies! the class is session based you can test if a user is logged in with this simple test:
Code:
if (!empty($_SESSION['user'])) echo "is logged in";
Atari ST fan
Posts: 8
52 credits Members referred : 0
« Reply #5 on: Oct 27, 2006, 06:32:48 AM »
This is really just a newbie trying to get used to your app. I got it checking. What I had wrong was I was used to putting the "axxiss_user_class.php" include with all the "$page_protect" stuff under it. So, for a non-protect page, I wasn't putting anything (and I figured, a session is a session, it should be able to check). But when I added the "axxiss_user_class.php" include, and not the "$page_protect" stuff, then it works (after I cleared all sessions (and cookies!) [I use FF, and use the Web Developer Toolbar extension], then closed my browser to completely start from scratch, it worked. I would say, "stupid me", but I still don't understand why it isn't just checking the session status (except perhaps if I'm not including that include, the page is clean, and the session info is removed perhaps?). I don't see that that has anything to do with AU. But again, that's just me as a newbie to sessions and AU.
Unfortunately, although I am now able to know if a user is logged in, it doesn't seem to remember it when the browser is closed, and I open it back up. It tells me I'm not logged in. I don't have anything clearing in the browser, as the session and the cookie are both set when I load the browser back up. But the page says I'm not logged in. Guess I'll browser around here... I seem to recall there being a thread on this "remember me".
Thanks.
Atari ST fan
Posts: 8
52 credits Members referred : 0
« Reply #6 on: Oct 27, 2006, 06:44:18 AM »
On the "Remember Me", I should clarify. I understand it's not supposed to keep me logged in when I reopen the browser, but the fields don't populate. I'm gonna check on those fields specifically in my form now.
Atari ST fan
Posts: 8
52 credits Members referred : 0
« Reply #7 on: Oct 27, 2006, 07:02:18 AM »
I must have started with an older login.php page, 'cause the values were like: