Jump to content

How would you suggest.....


Recommended Posts

How would you suggest that i record whether or not a member of my site is logged in?

I was thinking, that i add a column to my table that holds the users info, called onlinestatus or something. When they log in, i use a query to update it to online..... but how would i update it to offline if the member exits the browser?

Or is their a special method for doing this?

Thanks in advance for any help

Link to comment
Share on other sites

^ Dude, that's not what he's talking about.

You want to show members online, right? There's a PHP tutorial on PHP freaks that tells you how to do it. Basically, you set a cookie with the current time and every time a page is loaded you see if the cookie time is more than 5 minutes different from the current time. If it is, update the database with the new time they were on and update the cookie.

When you go to select from the database, just select the member whose "timeonline" is within in the last 5 minutes.
Link to comment
Share on other sites

I'm still having some trouble understanding this.
Lets say for examples sake, my table with the users information in it, that i want the online status to be stored in, hasn't got any fields relating to the whole online status issue in it.

Could someone tell me what fields i would need to add, what code i would need to put and where, and explain to me what the important pieces of code do and how they operate?

Sorry if thats kind of demanding, but i'm really quite stuck and would like to know what to do rather than aimless trial and error ;).

I would be really grateful for any further help, and thanks in advance!
Link to comment
Share on other sites

This can be done in 4 ways,
Sessions, cookies, databasing, or putting the info in some sort of  file, flat file, or excel sheet.
All you are needing to do is store a time period/
wait you are wanting instant record, to show when they are online, and when they are not.

Create a new column in your table, label it only.
then when they log on, have it automatically update that, to show online, wherever you want to display the online status pull it from the .
SELECT * FROM tablename WHERE online = 'yes';
then run that through all your queries or what not, at that time it will show yes, or no.  You can have a function or something
if ($online == "yes") {
whatever int hat if, if you wanted a picture to light up when there online you would put
<img src=""
whatever to have it appear when they are online, or you could put
echo "Online"
or whatever you wanted to do, then when they log off have it kill the script and say they are offline, have it change to no in the database, you might have some problems if people don't log off, so if you want another approach You can have it log them in when they log on, well actually, I don't know, I am stumped on how to set that up, if I think of anything further I Will let you know.
Link to comment
Share on other sites

I checked and these 2 things seem to be your only 2 viable solutions.
For the table add 1 column, name it
login- datetime
record the exact time and date they log in, then where you are displaying the data, pull the entire out of the database to display people that are online, something like assuming your table is named userinfo your date and time is labeled datetime
$select = "SELECT datetime FROM userinfo SORT BY datetype LIMIT 10;";
$query = mysql_query($select);
then whatever to display the results, you could probably come up with some php calculations to only pull out show the ones for the last 20 minutes, so you know that they all were atleast logged in within the past 10-20 minutes, the only other options would be flash, perl, c+, or something more advanced, or setting up a chat like system using perl, or cgi-based programming, and with that, using it on your site, or look for external programs for your server that can detect when people are connected to your site.
Link to comment
Share on other sites

Ok so i'm going to include at the top of each page, a script that records the time the page was loaded. Then i would class people who had loaded a page within a certain time range as Online and everyone else offline.

Thankyou everyone for the help :)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.