tags:

views:

130

answers:

2

Hello.

I have "Your latest 5 visits" at the home page of the user when he logs on. It works great without any problem.

But then i want to change it. I dont know how i should do this, but someway somehow only count the user 1 time at the time, and not e.g 10 times if he visits/refresh your profile.

So should i do this with a time checker? And for how long should it only count 1? When should second count? I need some idea for this, as I dont know if i should make it count 1 time per 10 minutes or 1 time per 1 minute..

So a good solution/giving a good realistic minute tip will answer the question.

A: 

Before anything else, you need to identify the visitor somehow -- either by IP address, a cookie or an username if accessing the profile requires logging in. And then a data structure to contain the visitation log for all profiles. For example, a SQL table where each row contains a visitor id, a profile id and the visitation time.

The last thing is the definition a time interval that counts as a single visit. For example 1 day -- if the previous visit happened less than 24 hours ago, you only update the time of the relevant SQL row. Otherwise you add a new row.

Edit Another way to define a new visit would be to check if the visitor has already been there since 00:00:00 of the current day or not. It would count 23:58 and 00:01 as separate.

Saul
Yes everything is ok until the third part.. Thats why i made this question. If i have an 24 hour limit, if a user visits at 00:01 pm , and then he visits again at 23:58pm it will only display that he have visited once. Maybe i should make it a hour limit?
Karem
No, you don't have to do that. Maybe I was not specific enough when I said "1 day". Use UNIX timestamp of mktime() function -- that way you simply check if the previous visit was more than 60 * 60 * 24 seconds ago or not. For output, you can format the UNIX timestamp with date() function. Once you get the logic working properly, then selecting the interval length is a matter of taste or conforming to other specifications if you have any.
Saul
but he has visited twice, once the first day and once the second day.
Phill Pafford
what logic? I am getting the logic working properly.. lol, that's why I am asking on how to count it the nicest way, before as a said in my previous comment, the 24 hours limit wont do
Karem
+1  A: 

There are a number of tutorials about 'Your Last Visit'

http://www.tizag.com/phpT/phpcookies.php

Phill Pafford
This looks like a promising solution - then the only question would be how far in the future to set the cookie expiration to consider "one session". The tutorial uses two months, but I can imagine as short as one hour if that's how Karem wants to count visits.
pjmorse
it's all up to @karem, not hard to implement that change at all
Phill Pafford