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] Quote Link to comment 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! Quote Link to comment 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.