lukelambert Posted August 2, 2006 Share Posted August 2, 2006 Sorry bpops, I haven't checked back here in a while. I completely overlooked the fact that it would not increase the post count the first time they visit (which will probably be the only time on individual items so that code was completely useless). I think I have fixed it now though.[code]<?php$cc_name = "counter"; // Name of the cookie$cc_expires = time() + 3600; // Expires in an hour$cc_item = "[" . $_GET['id'] . "]"; // Item identifier in [XX] format$cc_inc = false; // Whether the number of hits for that item should be incremented.if ($_COOKIE[$cc_name]){ $cc_value = $_COOKIE[$cc_name]; if (strpos($cc_value, $cc_item) === false) // If the user has not visited this page { $cc_value .= $cc_item; // Add the item to the cookie $cc_inc = true; }}else{ $cc_value = $cc_item; // Add the item to the cookie $cc_inc = true;}if ($cc_inc){ // Increase view count in database or whatever here // Something like: mysql_query("UPDATE item_table SET (hits = hits + 1) WHERE (id = " . $_GET['id'] . ")", $connection);}setcookie($cc_name, $cc_value, $cc_expires); // Create or re-create the cookie?>[/code] Link to comment https://forums.phpfreaks.com/topic/15851-making-a-simple-counter/page/2/#findComment-67989 Share on other sites More sharing options...
bpops Posted August 2, 2006 Author Share Posted August 2, 2006 thanks luke :)I had modified your code a bit, and now I'm having a new problem.. if you're interested in taking a look, i Have another post here:[url=http://www.phpfreaks.com/forums/index.php/topic,102741.0.html]http://www.phpfreaks.com/forums/index.php/topic,102741.0.html[/url]But I will try your new code as well and see if for some reason that fixes this strange problem I'm having.thanks! Link to comment https://forums.phpfreaks.com/topic/15851-making-a-simple-counter/page/2/#findComment-67994 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.