how to dis visitor online(php)

reimo's Avatar, Join Date: Feb 2011
Newbie Member
please i need a help, i want a php script that help me display the numbers of visitors in my site and to display logged in users and guest.
thank for being of help.
underground_devil's Avatar, Join Date: Jan 2011
Go4Expert Member
i can make it according to need because its long script so i cant be send here
ManzZup's Avatar, Join Date: May 2009
Skilled contributor
as this is something exactly i was doing for the past few days i can help
as i figured, the best and the easiest way to achieve this is using Jscript, where a periodical updator will update the the availability of the user
this is okay for ma chat script, but i dunno whether its okay with you, but i assure that it's mostly accurate than the previous method i used: of keeping the track of the user using a cookie and the work done by the user

but sorry im in a kindda hurry
so basically the logic is,
when the user sign in-> you take him to a new page ex:homepage
then the user is added to the online table
and in the header of the site, you put the update code, or a jS AJAX request every 30sec. to update the time() of the database

and peridically, add another check, mostly a AJAX request to delete the records which have the time() filed updated more than before 1 minute

so that's it D
hope you understand, and the code is rather simpler and may be you can figure it out yourself
however ill write it seperatly later [i ave it with the core files of the chat scirpt so that it takes time to make it as standalone]
shabbir like this
pein87's Avatar
Ambitious contributor
You need to set up either a session for every person or a cookie and have each time one is created stored in an array based on its user type. Then count each array's length for the total. Once it expires though you need to remove that index from the stack.