简体   繁体   中英

How to Count Page views by unique IP

I have a video playing page where I want to count video views. Currently I am updating page views with:

mysql_query("UPDATE video set views = views+1 where videokey = '$key'")or die(mysql_error());

but it's updating continuously from one IP. I want to make one view by each unique IP and I don't want to put user's IP in database and don't want to check user's IP from database then update view. Is there any way to count video views with out query to database for existing current IP?

Give them a $_COOKIE which makes above query not fire.

It isn't bulletproof, but it's something.

Well it depends. Will it be reliable ? no, but may shelter you from sensle incrementations...

If you want to go this road I would propose global session . It depends how long your sessions gonna last, but it should provide some protection from recounting the same ip if somebody refreshed etc. In the long run its still not persistent(and that's key) and a huge array of ips might kill your server.

Bear in mind its switched off so go see your php.ini before you start.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM