<?php
include 'php/dbconnect.inc.php'; 
//include 'php/errortrap.inc.php'; 

#function file_get_contents($filename) {
#  $fd = fopen($filename, "r");
#  $content = fread($fd, filesize($filename));
#  fclose($fd);
#  return $content;
#}


function file_put_contents($filename, $content) {
  $handle = fopen($filename, 'w'); 
  fwrite($handle, $content); 
  fclose($handle);
}

session_start(); 

$db = new DbConnect("localhost","minidischits","","minidisc",$error_reporting=true);
$db->open() or die($db->error());

if (!session_is_registered("counted")) { 
  $db->query("UPDATE simplecount SET count=(count + 1) WHERE count_id=1"); 
  $db->query("SELECT count FROM simplecount WHERE count_id=1");
  while ($row=$db->fetcharray()) {
    file_put_contents("/home/minidisc/public_html/hitcount", $row[0]);
  }
  session_register("counted"); 
} 
$count = file_get_contents("/home/minidisc/public_html/hitcount");
echo "document.write('",$count,"')";
?>

