Page 1 of 1

Visitors Now Online

Posted: Wed May 14, 2008 9:44 am
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?

Re: Visitors Now Online

Posted: Wed May 14, 2008 9:48 am
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

Re: Visitors Now Online

Posted: Wed May 14, 2008 9:54 am
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

Re: Visitors Now Online

Posted: Wed May 14, 2008 9:55 am
by aceconcepts
I like. One line of code :D

Re: Visitors Now Online

Posted: Wed May 14, 2008 10:18 am
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;

Re: Visitors Now Online

Posted: Wed May 14, 2008 10:26 am
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.

Re: Visitors Now Online

Posted: Wed May 14, 2008 10:39 am
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?

Re: Visitors Now Online

Posted: Wed May 14, 2008 11:00 am
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...

Re: Visitors Now Online

Posted: Wed May 14, 2008 11:36 am
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=