|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Chop Chop
|
PHP Questions
These are in addition to the time question in my other thread (still have not figured that out).
--Login Stuff-- How do I create an effective "Remember Me" selection on the login form? I have a field in the user database called "loggedin" which is set to "1" when the user logs in and is set to "0" when the user logs out. However, if the user closes the browser and is no longer at the site, it still says the user is logged in. How do I keep the user from being on the "Logged In" section all the time. Thanks |
|
|
|
|
|
#2 |
|
Come in Ray...
Join Date: Sep 2004
Posts: 1,668
|
If you are tracking this in a database, really the more effective method may be to update a time when they last performed an activity. This way if they haven't done something for X amount of time you can assume they have logged off.
Not 100% effective, but it should be good enough. |
|
|
|
|
|
#3 |
|
Chop Chop
|
So whenever the user makes a post, or sends a PM or changes their theme, I make the last_activity field = NOW(), right? How do I check to see if the last_acticity field is equal to of greater than the target time when I assume they have logged out?
Also, how do I make the remember me script? Thanks a ton! |
|
|
|
|
|
#4 |
|
Come in Ray...
Join Date: Sep 2004
Posts: 1,668
|
Right, whenever anything is done, you update a field in your database to the current time. Then when you need to see if they are logged in, you can compare the current time to the time they have logged in the database.
Remember me is usually handled through cookies. Check out php's setcookie function. I usually use 30 days as the default remember me time which would be (time()+60*60*24*30) |
|
|
|
|
|
#5 |
|
Chop Chop
|
OK, I got the remember me to work. I just needed to check to see if the cookie was set at the top of each page.
How do I check the users last_activity field against the current time? I'm kind of clueless about that. Also, is there any way to update the last_activity field when the user visits a page? Instead of having it everytime they do something. Because, they could still be logged in, but not be posting (or whatever). Would it be like this at the top of each page: PHP Code:
|
|
|
|
|
|
#6 |
|
Come in Ray...
Join Date: Sep 2004
Posts: 1,668
|
Yes, you would have a query like that at the top of every page you want to track actions for. To get the time difference, query the DB for your last_activity field and subtract it from the current time.
Since you are storing the last_activity as a date/time, you will need to use the strtotime function. Your statement would look like: $lapse = time() - strtotime($rs_row->last_activity) |
|
|
|
|
|
#7 |
|
Chop Chop
|
I got the last_activity to be set correctely. Thanks.
How do I check the current time against a certain user? PHP Code:
Thanks! |
|
|
|
|
|
#8 |
|
Chop Chop
|
OK, that didn't work. I'm confused. What do I do after I find the $lapse?
Thanks! |
|
|
|
|
|
#9 |
|
Member (9 bit)
|
You should get rid of the loggedin field in your database. Once the user leaves the site, because of the way PHP works, there is no way to change anything in the database to reflect that, unless you wrote a script that runs every few minutes and checks every single user in the database.
You need to decide on a certain amount of time of inactivity that results in a user being marked as "inactive." Then, if you need to get a list of logged out users, you just do a MySQL query searching for all users with a last_activity time of more than x minutes ago. |
|
|
|
|
|
#10 |
|
Come in Ray...
Join Date: Sep 2004
Posts: 1,668
|
catacon,
There is no way this will ever be true: $lapse = time() $lapse is intended to be (current time - last activity). Also, I was making the assumption that last_activity in your database is a Date/Time field and you are pulling it from the database using a query such as: SELECT last_activity FROM users WHERE id=$user_id (not using any MySQL date/time formatting functions) This gives you the information in a format the php function strtotime() can recognize. Your if statement should be something like: if ($lapse > [some amount of time in ms]) |
|
|
|
|
|
#11 | |
|
Chop Chop
|
Quote:
|
|
|
|
|
|
|
#12 |
|
Member (9 bit)
|
Hmmm.
Something like: SELECT * FROM users WHERE last_activity < 300000 Would find all users that were active in the last 5 minutes (300000 is 5 minutes in milliseconds). I haven't had any time to test this or anything, but I'm pretty sure that's what you're looking for. |
|
|
|
|
|
#13 |
|
Chop Chop
|
Isn't 5 minutes 30000 in milliseconds? 5m * 60s * 100ms = 30000? Also, what should last_activity be, datetime, time, etc.? Thanks!
|
|
|
|
|
|
#14 |
|
Member (9 bit)
|
Urrgh, I wrote that query wrong...
It *should* be SELECT * FROM users WHERE (curtime() - last_activity) < 300000 And according to Google, 5 minutes in 300000 milliseconds. You should set last_activity as a "time," I believe--I seem to have forgotten which types to use in MySQL, hopefully someone else can help with that. |
|
|
|
|
|
#15 |
|
Chop Chop
|
Still having a problem. Whenever I call the check_active function:
PHP Code:
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|