ted_chou12 Posted December 16, 2006 Share Posted December 16, 2006 below is a counter php script:[code]<?php$counter = ("$category/topic$number-counter.php");$hits = file($counter);$hits[0] ++;$fp = fopen($counter , "w");fputs($fp , "$hits[0]");fclose($fp); ?>[/code]but it only records the hits, so the number gets very big, and not very practical at all...Can anyone suggest me how to change it to unique hits, so it only records 1 hit per IP Adress? thanks Ted Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted December 16, 2006 Share Posted December 16, 2006 use a database it would help a lot more Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted December 16, 2006 Author Share Posted December 16, 2006 but i dont have one. in fact, i dont use db at all...all my records are in txt files Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted December 16, 2006 Author Share Posted December 16, 2006 actually, session count would be much better, does anyone know how that works? Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted December 16, 2006 Author Share Posted December 16, 2006 okay, ive done it.here[code]<?phpif ($_SESSION["forumtopic$number"] != "counted") {$counter = ("$category/topic$number-counter.php");$hits = file($counter);$hits[0] ++;$fp = fopen($counter , "w");fputs($fp , "$hits[0]");fclose($fp);$_SESSION["forumtopic$number"] = "counted";}?>[/code]Experts please check if i had done correctly,begginers please dont hesitate to put them on your site, but remember *this is session counter, so same ip address can still be counted again after the session expires, however, i personally believe this is better than either simple counter, or unique counter, because session counter is my new invention...haha ;Dthanks Quote Link to comment Share on other sites More sharing options...
taith Posted December 16, 2006 Share Posted December 16, 2006 yes... that does seem to be done right... but if you were wanting to further improve it... you may want to try using cookies instead of sessions...... Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted December 16, 2006 Author Share Posted December 16, 2006 oh, you can do this with cookies as well? could you please teach me how it works? really want to learn more :PThanks Ted. Quote Link to comment Share on other sites More sharing options...
taith Posted December 16, 2006 Share Posted December 16, 2006 not tested... but this should work[code]<?phpif($_COOKIE["forumtopic$number"] != "counted"){ $counter = ("$category/topic$number-counter.php"); $hits = file($counter); $hits[0] ++; $fp = fopen($counter , "w"); fputs($fp , "$hits[0]"); fclose($fp); $inTwoMonths = 60 * 60 * 24 * 60 + time(); setcookie("forumtopic$number","counted",$inTwoMonths);}?>[/code] Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted December 16, 2006 Author Share Posted December 16, 2006 thats so coolThanks by the way.Just learnt a new stuff today :D 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.