subhomoy Posted January 13, 2012 Share Posted January 13, 2012 Hiii i got a image hosting script but the problem i'm not able to solve is that in the show image page, the page views counter is not showing unique views. If we refresh the page 100 times from same ip, it shows (views=100)... Can any one help me with it... The views are stored in the database of the respective users... can anyone help me to get unique views per 24 hrs per ip.... The code is... //UPDATE VIEWS COUNT AND LAST ACCESS DATE $views = $row['views'] + 1; $access = date("y-m-d"); $r = mysql_query("UPDATE `images` SET views = '$views', access = '$access' WHERE id = '$id' "); $imguserid = getUserId($id); $own = false; if ($imguserid != -1) { if ($userid == $imguserid) $own = true; $r = mysql_query("SELECT username FROM `members` WHERE id = '$imguserid'"); $row1 = mysql_fetch_row($r); $username = $row1[0]; } else $username = "Anonymous"; echo "<center>"; echo "<br><LABEL id='title'>Views:</LABEL> $views"; echo "<br><LABEL id='title'>Date Added:</LABEL> {$row['date']}"; if needed i can supply the full script to the person who can help me... You can check the demo in [ http://torrentz.0fees.net/wussa/show-image.php?id=c7693c02c3ad2fafe5f5d3f00263a68a ] The full page is attached below.... Quote Link to comment https://forums.phpfreaks.com/topic/254931-page-views-not-working/ Share on other sites More sharing options...
joel24 Posted January 13, 2012 Share Posted January 13, 2012 if you want to distinguish between views per I.P. address you'll need a table with IP datetime imageID And make IP / imageID a composite primary key and use a INSERT ON DUPLICATE UPDATE query which will update the view datetime and just leave one view per IP OR you can have a unique auto_increment primary key and store every image view and then use a mysql query to select distinct Quote Link to comment https://forums.phpfreaks.com/topic/254931-page-views-not-working/#findComment-1307151 Share on other sites More sharing options...
subhomoy Posted January 13, 2012 Author Share Posted January 13, 2012 if you want to distinguish between views per I.P. address you'll need a table with IP datetime imageID And make IP / imageID a composite primary key and use a INSERT ON DUPLICATE UPDATE query which will update the view datetime and just leave one view per IP OR you can have a unique auto_increment primary key and store every image view and then use a mysql query to select distinct Can you please give the source code..... Quote Link to comment https://forums.phpfreaks.com/topic/254931-page-views-not-working/#findComment-1307227 Share on other sites More sharing options...
joel24 Posted January 14, 2012 Share Posted January 14, 2012 //here's the sql to count distinct views for the current image SELECT COUNT(DISTINCT ip) as `count` FROM `imageViews` WHERE imageID='$currentImage'; //each time someone views the image, run a sql code to store their IP address, the time/date and the imageID in the sql table. Quote Link to comment https://forums.phpfreaks.com/topic/254931-page-views-not-working/#findComment-1307462 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.