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 Link to comment https://forums.phpfreaks.com/topic/30869-solved-instead-of-hits-i-want-unique-hits-php-counter/ 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 Link to comment https://forums.phpfreaks.com/topic/30869-solved-instead-of-hits-i-want-unique-hits-php-counter/#findComment-142350 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 Link to comment https://forums.phpfreaks.com/topic/30869-solved-instead-of-hits-i-want-unique-hits-php-counter/#findComment-142352 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? Link to comment https://forums.phpfreaks.com/topic/30869-solved-instead-of-hits-i-want-unique-hits-php-counter/#findComment-142354 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 Link to comment https://forums.phpfreaks.com/topic/30869-solved-instead-of-hits-i-want-unique-hits-php-counter/#findComment-142360 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...... Link to comment https://forums.phpfreaks.com/topic/30869-solved-instead-of-hits-i-want-unique-hits-php-counter/#findComment-142362 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. Link to comment https://forums.phpfreaks.com/topic/30869-solved-instead-of-hits-i-want-unique-hits-php-counter/#findComment-142363 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] Link to comment https://forums.phpfreaks.com/topic/30869-solved-instead-of-hits-i-want-unique-hits-php-counter/#findComment-142368 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 Link to comment https://forums.phpfreaks.com/topic/30869-solved-instead-of-hits-i-want-unique-hits-php-counter/#findComment-142369 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.