Not really that simple.

You can't use the HTTP_REFERER, because it's not set when the user refreshes
(at least on my browser, so at best it will be unreliable).

Common ways to prevent such things happening (like voting for a pic or song
or poll more than once) are usually done with either:

1. logging IP address', and ignoring two votes within a reasonable period of
time from the same address -- this has a high overhead of data, and isn't
failsafe, because IP address' are notoriously unreliable.

2. dropping a cookie onto the users computer, basically saying "read this
one", so that the vote is only counted if the cookie isn't there...
obviously users can choose to block cookies, or delete them, so this isn't
reliable either

3. sessions... if you maintain a site-wide session with each of your users
(done with either a session id in the url, or with a cookie), you can keep
track of which news items have been read on the server side with session
variables.  again, this isn't 100% reliable, because the user could delete
the session cookie or delete the session # from the URL (both making the
user appear as a new user)


And that's about it.


So, you've got a choice of three options, none of which are bullet proof at
all.  I personally like the session one (because all the user knows is that
they're in a session, not that each news read is being logged), but you have
to understand that you will not get it perfect, ever.

I could write a PHP script, or even a client-side apple script or schedule
which access' your URL every 5 mins... no cookies, no sessions, no nothin',
and i'd get huge numbers :)


If I was trying for the best possible outcome, I think I'd log an IP
address, timestamp and user agent string (even if it's null), but rely on
sessions first...  Needless to say though if your news is being read a lot,
you'll have a lot of data to store, clean out, etc.


Justin



on 15/02/03 5:08 PM, Pag ([EMAIL PROTECTED]) wrote:

> 
> Hi,
> 
> I have a news site where i want to track how many "visits" or reads each
> individual news has. I have a main list with all the titles, then clicking
> on them shows the details of the specific news, only then the counter for
> that particular news is increased. The problem is, if the user does a
> refresh while at the details, the counter is increased again. How can i
> prevent this from happening?
> 
> I thought it would be something like a unique counter problem, but its
> like having a "counter problem" for each news i have. :-P
> 
> What would be nice, if it exists, is to check if the user is doing a
> refresh or coming from somewhere else. If its a refresh, the counter would
> simply not increase. That would be sufficient to keep the
> i-want-my-news-to-have-the-higher-number-of-visitors author, from having
> his way.
> 
> Thanks.
> 
> Pag
> 
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to