« I Fixed the Formatting Problem | Main | Fixing the Hit Counter »

Friday, July 31, 2009

I Posted My First php Program

I posted my first php program today. It is just a simple hit counter for my web page:

www.thekimerers.com/brian/

I downloaded most of it from the net, but then I had to make a change in order to get it to work properly. Here is the complete file:

?php
  $file = 'counter.txt';

  if(!file_exists($file))
  {
  $handle = fopen($file, 'w');
  fwrite($handle, 0);
  fclose($handle);
  }

  $count = file_get_contents($file);
  // Trim the newline of one is there
  $count = trim($count);
  $count++;

  if(is_writable($file))
  {
  $handle = fopen($file, 'w+');
  fwrite($handle, $count);
  fclose($handle);
  }
  else
  {
  echo 'Could not increment the counter!
'; } echo number_format($count); ?>

I had to change my index page from index.shtml to index.php to get it to work.

What does this have to do with this blog?

Some day I will probably change this blog from .html files to .php files and try to make it a bit smarter.

Stay tuned.

Posted by Brian S. Kimerer at 11:20 PM

This site and all of its contents are copyright Brian S. Kimerer 2009