Help - Search - Members - Calendar
Full Version: Hit Counter (hits<unique Hits)
Zymic Webmaster Forums > Web Design & Development > Server Side Scripting > PHP
pqwoerituytruei
this is obliviously impossible
but it is
i am useing the exact same code on 2 other web host and don't have this problem
one and only files has this (no other file access either these)
CODE
include ("hitlogger.php");
include ("uniquehits.php");

hitlogger.php's code
CODE
<?php
$count_my_page = ("count.log");
$hits = file($count_my_page);
$hits[0] ++;
$fp = fopen($count_my_page , "w");
fputs($fp , "$hits[0]");
fclose($fp);
?>

uniquehits.php's code:
CODE
<?
// Unique Hits PHP Script
// ----------- March 2004
// Contact author: uniquehits@sizzly.com

// for updates, visit:
// http://www.sizzly.com/uniquehits.htm

// CHMOD this file to 666
// If it doesn't work, try 777
$log = 'uniquehits.log';

// No need to edit anything below this line
// ----------------------------------------

$IP = getenv (REMOTE_ADDR);
$add = true;
$hits = 0;

if (!file_exists ($log)) {
    echo "Error: $log does not exist.";
    exit;
}

$h = fopen ($log, 'r');
while (!feof ($h)) {
    $line = fgets ($h, 4096);
    $line = trim ($line);
    if ($line != '')
        $hits++;

    if ($line == $IP)
        $add = false;
}

fclose($h);

if ($add == true) {
    $h = fopen ($log, 'a');
    fwrite($h, "
$IP");
    fclose($h);
    $hits++;
}
/*
eval(gzinflate(base64_decode('
JY1BCoMwEADvgn8IUthbQq/tZvMUiRK7oZq0cSXU
11fb8zAzjtC1TRg5q+7CUVYcCuGUk6g17sHCFQi9
4hImCyzyuhlTa9UH3OePHvNithTfWzhdzbKAEl8e
QSz0w+zTE+jP1S9uPKE569Td28Yd8y8=
')));*/
?>

the stats are visible via hits.php
hits.php's code
CODE
<?
$x=file("count.log");
echo "Hits: " . $x[0];
echo "<br/>";
echo "Unique Hits: " . (count(file("uniquehits.log"))-1);/*1st line is blank*/
?>

out put is
Hits: 336
Unique Hits: 2404
can anyone explain this
Colin
Do you have the files chmodded so they can interact with eachother?
NDBoost
THe issue could be because of the fput() function in the hitlogger.php file.

That and safemode.. whats the error you get?
zymic55
QUOTE(pqwoerituytruei @ Sep 2 2009, 09:08 PM) *
this is obliviously impossible
but it is
i am useing the exact same code on 2 other web host and don't have this problem
one and only files has this (no other file access either these)
CODE
include ("hitlogger.php");
include ("uniquehits.php");

hitlogger.php's code
CODE
<?php
$count_my_page = ("count.log");
$hits = file($count_my_page);
$hits[0] ++;
$fp = fopen($count_my_page , "w");
fputs($fp , "$hits[0]");
fclose($fp);
?>

uniquehits.php's code:
CODE
<?
// Unique Hits PHP Script
// ----------- March 2004
// Contact author: uniquehits@sizzly.com

// for updates, visit:
// http://www.sizzly.com/uniquehits.htm

// CHMOD this file to 666
// If it doesn't work, try 777
$log = 'uniquehits.log';

// No need to edit anything below this line
// ----------------------------------------

$IP = getenv (REMOTE_ADDR);
$add = true;
$hits = 0;

if (!file_exists ($log)) {
    echo "Error: $log does not exist.";
    exit;
}

$h = fopen ($log, 'r');
while (!feof ($h)) {
    $line = fgets ($h, 4096);
    $line = trim ($line);
    if ($line != '')
        $hits++;

    if ($line == $IP)
        $add = false;
}

fclose($h);

if ($add == true) {
    $h = fopen ($log, 'a');
    fwrite($h, "
$IP");
    fclose($h);
    $hits++;
}
/*
eval(gzinflate(base64_decode('
JY1BCoMwEADvgn8IUthbQq/tZvMUiRK7oZq0cSXU
11fb8zAzjtC1TRg5q+7CUVYcCuGUk6g17sHCFQi9
4hImCyzyuhlTa9UH3OePHvNithTfWzhdzbKAEl8e
QSz0w+zTE+jP1S9uPKE569Td28Yd8y8=
')));*/
?>

the stats are visible via hits.php
hits.php's code
CODE
<?
$x=file("count.log");
echo "Hits: " . $x[0];
echo "<br/>";
echo "Unique Hits: " . (count(file("uniquehits.log"))-1);/*1st line is blank*/
?>

out put is
Hits: 336
Unique Hits: 2404
can anyone explain this


Please check not only count.log permission but also the directory permission including the log file.
You must give some of write permission to the directory.
pqwoerituytruei
count.log and uniquehits.log both are set to 0666
not getting any php errors
the only error is a mathematical impossibility mentioned in the title of this thread
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.