Hey everyone, I just joined the forum because I am planning on learning PHP to eventually use with MySQL. I've just started out with web design and am designing my first site.

I'm trying to implement a simple hit counter for my index.html page. I've used a tutorial that I found. I have three files: index.html, counter.php and hits.txt. Here's their contents:

index.html

<div id="content">
     <h2>Header 2</h2>
     <h3>Header 3</h3>
     <p>hit count should appear below</p>
     <?php include("counter.php"); ?>
     <p>hit count above</p>
</div>

counter.php

<?php
$count_my_page = ("hits.txt");
$hits = file($count_my_page);
$hits[0] ++;
$fp = fopen($count_my_page , "w");
fputs($fp , "$hits[0]");
fclose($fp);
echo $hits[0];
?>

and hits.txt


They all sit in the root directory of my domain. I have messed around alot before asking here - I tried making a php.ini file with settings from my host and placing that in the root also. I tried making a .htaccess file with some settings from the host but that gave me the T_STRING on line 1 parse error. With my limited knowledge I think that I need to change some settings as when I hit "view source" in IE on index.html I can still see the php code, thus it isn't getting interpreted.

If anyone could help, that would be great!

zfind.

    $hits[0] ++ should be $hits[0]++

    fputs($fp , "$hits[0]"); should be fwrite($fp, $hits[0]);

      Write a Reply...