Return to iWEBTOOL

Go Back   iWEBTOOL Talk > The Web and your Website > Programming > PHP
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
 
Welcome to iWEBTOOL Talk, where you talk about webmaster-related stuff.
 
Discuss topics which interest you.
With over thousands of threads (topics), we're sure you'll find something that'll interest you.
Ask for help whenever you need it.
We have thousands of members who are available to help you if you need it.
It's absolutely FREE!

 1  Register           2  Browse the board           3  Discuss whatever may interest you!
 


Closed Thread
 
Thread Tools Search this Thread Display Modes
Old 12-27-2005, 05:53 PM   #1
compuXP
Retired Member
 
compuXP's Avatar
 
Join Date: Dec 2005
Posts: 139
compuXP will become famous soon enough
Red face Tracking Online Users

I have a tough question, IMO.

I want to keep track of all visitors to a webpage - whether logged in or guest, and know what URL they are on.

Similar to a forum's "users online" feature... I guess that each page load, you should store the URL and IP in a database, then on the next time a page is loaded, delete entries older than 5 minutes (as we could assume they have left then) ... but I dunno how to do this?

Thanks,
-Matt
__________________
Retired Moderator/Member/Friend/Helper - it was great working with all of you!
compuXP is offline  
 
This is an Ad Revenue Sharing forum Place your advert here
SEO Checklist
Get yourself better ranking with
our "Do-it-Yourself" SEO Checklist.
Click Here
Old 12-27-2005, 08:07 PM   #2
bbott
Member
 
bbott's Avatar
 
Join Date: Dec 2005
Location: New Jersey
Posts: 111
bbott will become famous soon enough
Send a message via AIM to bbott Send a message via MSN to bbott
Default Re: Tracking Online Users

What is the purpose of this? Why don't you just instal AWStats on your server? It pretty much tells you how many visitors each page has, whether they entered or exited through that page, etc. etc.

It's not real time stats though. Check our hotscripts.com if you need something like you described.
__________________
Storage Sheds
bbott is offline  
Old 12-27-2005, 11:29 PM   #3
compuXP
Retired Member
 
compuXP's Avatar
 
Join Date: Dec 2005
Posts: 139
compuXP will become famous soon enough
Default Re: Tracking Online Users

Bbott, perhaps you misunderstand me. I have and use AWstats (even though I use and prefer Analytics), but I want the webpage to tell me what users are where, like it says on forums:

Currently Active Users Viewing This Thread: 3 (2 members and 1 guest)
__________________
Retired Moderator/Member/Friend/Helper - it was great working with all of you!
compuXP is offline  
Old 12-28-2005, 02:47 AM   #4
rohan2kool
Member
 
rohan2kool's Avatar
 
Join Date: Dec 2005
Posts: 132
rohan2kool will become famous soon enough
Default Re: Tracking Online Users

It's quite simple. Don't worry, I'll make a program with PHP + MySQL for you.

The basic idea is the same as u said. it's damn simple.
rohan2kool is offline  
Old 12-28-2005, 03:11 AM   #5
compuXP
Retired Member
 
compuXP's Avatar
 
Join Date: Dec 2005
Posts: 139
compuXP will become famous soon enough
Default Re: Tracking Online Users

I figured it is. I just need to know the MySQL query to deal with the time.
__________________
Retired Moderator/Member/Friend/Helper - it was great working with all of you!
compuXP is offline  
Old 12-30-2005, 11:41 AM   #6
rohan2kool
Member
 
rohan2kool's Avatar
 
Join Date: Dec 2005
Posts: 132
rohan2kool will become famous soon enough
Default Re: Tracking Online Users

Well, there is no such query to deal with time and even if there is, I don't know it.

You can make a table with a filed as 'timestamp' instead of int, varchar etc. It's a datatype. For ex:

Code:
create table mytable(id int auto_increment, name varchar(100), time timestamp, primary key(id);

Here, whenever you enter any data in the table, the time field will automatically contain a string as it's data which denotes the time of entry. It is a 14 digit number. For ex:

20051230145858
The first 4 digits refer to the year i.e 2005
The next 2 digits refer to the month i.e 12 i.e December
The next 2 digits refer to the date i.e 30
The next 2 digits refer to the hour i.e 14 i.e 2 pm
The next 2 digits refer to the minutes i.e 58
And the last 2 refer to the seconds i.e 58

So, the time of this entry was 30th December, 2005 @ 2:58:58 p.m
To get the time(in seconds) between two activites, as in your case you the difference between current time and the time of entry of users and delete all entries older than 5 minutes, all you need to do is convert the MySQL timestamp in the no. of seconds passed since January 1, 1970 (as returned by the php function, time() ), subtract it from the current time by using the function time() and see whether the difference is greater than 300 (i.e 5 minutes). To convert do the following procedure:

Code:
$sql = "select id, time from mytable"; $row = @mysql_fetch_array($sql while($row = mysql_fetch_array["row"]) { $datetime = $row["time"]; //Get the time field from the database $year = substr($datetime, 0, 4); //Parse values for hour, minutes etc. from the string $mon = substr($datetime, 4, 2); $day = substr($datetime, 6, 2); $hour = substr($datetime, 8, 2); $min = substr($datetime, 10, 2); $sec = substr($datetime, 12, 2); //And then, conver them to the timestamp using the mktime function $regTime = mkTime($hour, $min, $sec, $mon, $day, $year); //Get the difference in time $difference = time() - $regTime; if($difference > 300) { $sql = "delete from mytable where id="; //Execute query to remove if time period is greater than 5 minutes $sql .= $row["id"]; $rs = @mysql_query($sql, $conn); } }

In the while loop, the array you get will be of subsequent rows as and when the loop repeats itself i.e at every iteration. Hence the check for a time difference of 5 minutes will bee conducted for every user. Now whenever a user visits the page, all you need to do is check whether the user alreay exists in the activity table and then either update or create a row with a psuedo entry, so that the time of entry is automatically entered by the MySQL server. This can be done by:

Code:
$sql = "select * from mytable where user="; $sql .= $username; //Where $username is the user logged in. Also, it can be 'guest' or something else if username ='' $rs = @mysql_query($sql, $conn); if(mysql_num_rows($rs) != 0) { //User is already in the table. Just update the timestamp and IP(if needed) $sql = "update mytable set user="; $sql .= $username; //A psuedo entry. No actual change, just that time will be changed automatically } else { //User is not in the table. Create a row //You can do that, most probably, so i leave it to you }

Just do it on every page and share a common table, hence you can monitor the activity through the table. Also, you can use $REMOTE_ADDR as a variable which returns the IP address of the user.

Note: You can also manually enter time into the 'time' field, by initiating the 'time' field as a varchar(11) and filling in data returned by the time() function.

Phew... I hope my explaination and short - tutorial till now has helped you. Please give your comments on it. Thanks a lot...
rohan2kool is offline  
Old 12-30-2005, 02:20 PM   #7
compuXP
Retired Member
 
compuXP's Avatar
 
Join Date: Dec 2005
Posts: 139
compuXP will become famous soon enough
Default Re: Tracking Online Users

Wow, I don't have time to read it now but I will shortly.

Although, I did find this syntax in an SQL query:

... WHERE date_sub('$ts', INTERVAL 5 MINUTE) > '$ts'

Where $ts is the current timestamp. However, this doesn't seem to return any results in a SELECT query.

I'll read your tutorial shortly. Thanks
__________________
Retired Moderator/Member/Friend/Helper - it was great working with all of you!
compuXP is offline  
Old 12-31-2005, 07:37 AM   #8
rohan2kool
Member
 
rohan2kool's Avatar
 
Join Date: Dec 2005
Posts: 132
rohan2kool will become famous soon enough
Default Re: Tracking Online Users

well, i believe that there are two types of timestamps: 1. UNIX timestamp (a 11 digit number giving the no. of seconds elapsed since January 1, 1970) 2. timestamp datatype in SQL database(a 14 digit number represnting the year, date, month and time). I believe ur using the wrong timestamp here. Refer to my tutorial in this thread. I have discussed both these timestamps....
rohan2kool is offline  
Old 01-02-2006, 04:52 PM   #9
AidenJ
Regular Member
 
AidenJ's Avatar
 
Join Date: Dec 2005
Posts: 103
AidenJ will become famous soon enough
Default Re: Tracking Online Users

Have you tried tearing apart PHPBB or something like that to see what they are doing? I know it uses a 5 minute query. I have not gotten in depth with it, but I have expanded it to include pages on my site outside the forums proper. If I were to do it, I would probably just start there.

This is one thing I really miss about the old multi-user BBS days. I loved being able to see how many people were online and exactly what they are doing. The web really doesn't readily provide that kind of feedback, and it is something I would like to do as well.
AidenJ is offline  
Old 01-03-2006, 09:15 AM   #10
rohan2kool
Member
 
rohan2kool's Avatar
 
Join Date: Dec 2005
Posts: 132
rohan2kool will become famous soon enough
Default Re: Tracking Online Users

have a look at my tutorial. i made a page based on it, and well it works nicely...
__________________
Eat healthy, Stay Fit, Die Anyway.
--==--
If there is a man who knows everything about women, there is a Windows distribution without bugs.
rohan2kool is offline  
Old 04-08-2006, 12:27 PM   #11
loanskey
Smurf
 
loanskey's Avatar
 
Join Date: Mar 2006
Posts: 23
loanskey will become famous soon enough
Default Re: Tracking Online Users

the five minutes funda is looks cool.
tell if if you are able to wright it down.
I have heard that all these stats can be counted if you use session VIA database.

I have never tried that. Like Vbulletin use it via database.
__________________
ZillR : Indian social Network
loanskey is offline  
Old 05-29-2006, 04:02 AM   #12
ruby
Newcomer
 
ruby's Avatar
 
Join Date: Feb 2006
Location: Perth, WA
Posts: 29
ruby will become famous soon enough
Default Re: Tracking Online Users

Check out the way OSC (www.oscommerce.com) handles its WHOS ONLINE feature. Its very neat and quick. I have coded my own for a couple of sites based on their design, modified to suit my own needs. Works a treat. I even identify bots crawling the site so I can tell the bots from the real users.
ruby is offline  
 
This is an Ad Revenue Sharing forum Place your advert here
Webmaster Tools Webmaster Tools Click Here
Closed Thread

(Threads which have no activity for more than 30 days are automatically closed.)



Quick Reply
Message:

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Referral Tracking HouseOfRock Programming 2 07-21-2006 07:53 PM
users online munt Discuss iWEBTOOL 8 04-02-2006 05:40 PM
IP tracking? dogofwar Help and Support 4 02-08-2006 01:02 AM


All times are GMT. The time now is 01:23 AM.


Powered by vBulletin v3.6.7 © 2008, Jelsoft Enterprises Ltd. SEO by vBSEO © 2006, Crawlability, Inc.