Visitors Now Online

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kusal
Forum Newbie
Posts: 14
Joined: Mon Oct 22, 2007 12:12 pm

Visitors Now Online

Post by kusal »

I need to know how can I track current guest visitors to my site and display it in the top of the page,
what functions do I need?
Is database needed for this? or can I use a text file?
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Visitors Now Online

Post by aceconcepts »

I use a database and it work perfectly for me.

You would need to update a database specific to a user's activity and thenset a $_SESSION[] variable as their status i.e. logged in
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Visitors Now Online

Post by VladSun »

Code: Select all

$count = `ls -l /var/lib/php5/ | wc -l`
:P :P :P

No DB, no file, nothing ... just Linux cmd shell ;)

PS: "/var/lib/php5/" is for the value of session.save_path in php.ini
Last edited by VladSun on Mon Jun 27, 2011 3:29 pm, edited 1 time in total.
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Visitors Now Online

Post by aceconcepts »

I like. One line of code :D
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Visitors Now Online

Post by VladSun »

Well, it's not ideal:
- it depends on session.gc_maxlifetime;
- it's for session management that uses file storage;

Also, there is an issue (bug?) - there is always one session file left in this directory, regardless of any *maxlifetime;
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Visitors Now Online

Post by aceconcepts »

I guess it also depends on the extent to which one will be taking "user tracking".

If you want to log user activity etc... then a database would be ideal.
kusal
Forum Newbie
Posts: 14
Joined: Mon Oct 22, 2007 12:12 pm

Re: Visitors Now Online

Post by kusal »

I cannot exactly figure out this,

lets say that user comes to my home page, then I will initialize a session like this $_SESSION['user'] = "Guest";
Now the problem is that how can I find all initialized $_SESSION['user'] from my server?
Then how do I know user left the my site?
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Visitors Now Online

Post by aceconcepts »

you can use a session id to keep track of unique guests

Code: Select all

 
$_SESSION['guestId']=session_id();
 
With regard to the guest leaving the site, this has been asked quite a few times - and well there is no way to acurately determine when a visitor leaves the site unless they log out.

However, the default lifetime of a session is 24minutes so i guess this solves your problem.

With regard to updating the database you would probably have to check the guest's session validity at a set time i.e. every 30 minutes etc...
suresh_2220
Forum Newbie
Posts: 23
Joined: Mon May 12, 2008 3:13 pm

Re: Visitors Now Online

Post by suresh_2220 »

You can add third party software (javascript code) inside your code. there is no need for any DB or txt file. the third party software will store visitor details in their server and result will display in your site. Please visit this URL http://www.google.co.in/search?hl=en&q= ... nter&meta=
Post Reply