Jump to content

[SOLVED] instead of hits, i want unique hits (php counter)


ted_chou12

Recommended Posts

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
okay, ive done it.
here
[code]
<?php
if ($_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 ;D
thanks
not tested... but this should work

[code]
<?php
if($_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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.