I am trying to create an article based website using codeigniter. When any article is requested to fetch from database for viewing, I use the following code to mark the number of unique view of each article in a separate table called “hits”.
mysql_query("INSERT INTO hits(ip,article_slug,hitcount)
VALUES('$ip_address','$id',1)
ON DUPLICATE KEY UPDATE hitcount=hitcount+0");
I get the value of article_slug from $this->uri->segment(3);
Now the above query works fine but the problem is, in the database it adds one extra row for each unique article view and I have no idea where it is coming from. the table looks like this
Table: hits
ip article_slug hitcount
127.0.0.1 valid.png //<<no idea where the valid.png comes from 1
127.0.0.1 making-a-seo-friendly-url-for-a-cms 1
I am running it on localhost.Could you tell me how to get rid of creation of the extra row that is producing valid.png
Thanks in Advance 🙂
Does the page you’re requesting possibly contain an image link to ‘server.com/valid.png’ ? In which case if it doesn’t have a shortcuted static file access (.htaccess) it maybe interpretted by your front controller like any other request. Possibly light up firebug and check out all the http requests being sent.