Thanks verymuch it works, BUT it just inserts a hit into a blank page_name collumn if i type in a url if it has http://www.mysite.com/pagename (without a file extension) What can i do about that?
<?php
$dbase['host'] = 'localhost';
$dbase['user'] = 'jami3EETh';
$dbase['pass'] = 'hoiqueper';
$dbase['name'] = 'jami3EETh';
$dblink = mysql_connect($dbase['host'], $dbase['user'],$dbase['pass']);
mysql_select_db($dbase['name'], $dblink);
$hpage = $_SERVER['REQUEST_URI'];
$end = strpos($hpage, '.');
$hpage = substr($hpage, 0, $end);
// The previous three lines can become one with:
// $hpage = substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], '.'));
$sql = 'SELECT * FROM hit_counter where page_name = \''.$hpage.'\' limit 1';
$result = mysql_query($sql, $dblink);
$data = mysql_fetch_assoc($result);
// $data['page_id'] - This part of the array stores the ID of the record in the database for this page
// $data['page_name'] - This is the actual path & filename of the URL to which this record belongs
// $data['page_hits'] - This, surprisingly, is the number of hits the page above has received
if ($data) {
$data['page_hits']++;
$sql = 'UPDATE hit_counter SET page_hits = \''.$data['page_hits'].'\' where page_id = \''.$data['page_id'].'\'';
$result = mysql_query($sql, $dblink);
} else {
$sql = 'INSERT INTO hit_counter (page_id, page_name, page_hits) VALUES (\'\', \''.$hpage.'\', \'1\')';
$result = mysql_query($sql, $dblink);
}
?>