Number of visitors.

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
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Number of visitors.

Post by JellyFish »

How would I get the number of visitors on a php page? Let's say I have a php page that renders an image that has the number of unique visitors on the page and then saves that image to a location on my server. In order for me to do this I would need a way to count the number of visitors on my page.

How would I do this on the server-side with php?

Thanks for reading.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Number of visitors.

Post by aceconcepts »

Would you be counting unique visitors, hits or both?
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Re: Number of visitors.

Post by JellyFish »

Only unique. That is, the number of users online.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Number of visitors.

Post by aceconcepts »

You would need a comparable variable in a store (like a database). With this comparable variable you would also need something unique for each user (if they are registered users then their ID would work).

Once you have this you could simply compare the two variables to see whether user is has visited - if not then increement "visit variable" and update in database.
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Re: Number of visitors.

Post by JellyFish »

Hmm... How would I know when someone has exited my page? If I new of some way to do this I would be able to log when someones online and then log when they're not.

All I really need to be able to do is record when someones visited my page and then record when they've left my page.

What I'll do is count the number of visits and subject the counted number of 'un-visits'.
User avatar
lonelywolf
Forum Commoner
Posts: 28
Joined: Tue Jun 10, 2008 6:15 am

Re: Number of visitors.

Post by lonelywolf »

maybe you need using session ID to track clients.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: Number of visitors.

Post by superdezign »

JellyFish wrote:How would I know when someone has exited my page?
You can't know. All you can know is how recently they made a request to the server and received a response from the server. That's the internet for you. :P

Unless you use Ajax to check their online status constantly, but even that works similarly, just doesn't require any user interaction to accomplish.
Post Reply