shortysbest Posted July 5, 2010 Share Posted July 5, 2010 I am working on unique page view counter however i am running into this problem with my code. What i am trying to do is to create a unique view count per page and i have been attempting to do so a couple of ways. the current way i am doing it gets the users ip and gets the page they are on and inserts it into a single column in the database. table name is ips, column name is ip. inside of the ip column if the user is on the homepage it should insert a value that looks similar to this: 67.220.153.249 home or if they were on a page called shows it would look like this: 67.220.153.249 shows However with my current code it adds every view, not just unique view. So I need it to not add a view if the ip and page is already in the database, but to add 1 view if it isnt. So. I'm not sure why it isn't working correctly. I'm just getting impatient with it and was hoping i could get some help. Maybe if someone had an idea and wanted to completely recode it to work how i want that would be great, however if someone could just figure out the problem in my code and point me in how to fix it that would be great too Thanks <?php include('connect.php'); if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet { $ip=$_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy { $ip=$_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip=$_SERVER['REMOTE_ADDR']; } $page = $_GET['node']; if ($_GET['node']=="product"){ $itm = $_GET['id']; $ippage = $ip.' '.$page.' '.$itm; } else { $ippage = $ip.' '.$page;} $ipp = mysql_query("SELECT * FROM ips WHERE ip='$ippage'"); $ipf = mysql_fetch_assoc($ipp); if (mysql_num_rows($ipp) == 0) {} else { $query = mysql_query("UPDATE counter SET count=count+1 WHERE page='$page'"); if (mysql_affected_rows() == 0) { // No records updated, so add it $query = mysql_query("INSERT INTO counter SET page='$page', count=count+1"); } if($_GET['node']=="product") { $itm = $_GET['id']; $return = mysql_query("UPDATE itmcounter SET count=count+1 WHERE itm='$itm'"); if (mysql_affected_rows() == 0) { // No records updated, so add it $return = mysql_query("INSERT INTO itmcounter SET itm='$itm', count=count+1"); } }} ?> Quote Link to comment https://forums.phpfreaks.com/topic/206814-phpmysql-unique-view-counter-problem/ Share on other sites More sharing options...
shortysbest Posted July 6, 2010 Author Share Posted July 6, 2010 ideas? Quote Link to comment https://forums.phpfreaks.com/topic/206814-phpmysql-unique-view-counter-problem/#findComment-1081707 Share on other sites More sharing options...
premiso Posted July 6, 2010 Share Posted July 6, 2010 What was the point of quoting your original post? Afraid that we would not be able to see it? Quote Link to comment https://forums.phpfreaks.com/topic/206814-phpmysql-unique-view-counter-problem/#findComment-1081710 Share on other sites More sharing options...
shortysbest Posted July 6, 2010 Author Share Posted July 6, 2010 What was the point of quoting your original post? Afraid that we would not be able to see it? Oh actually didn't mean to quote all of it, meant to delete part of it. Quote Link to comment https://forums.phpfreaks.com/topic/206814-phpmysql-unique-view-counter-problem/#findComment-1081711 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.