Salve, ho trovato questo codice . servirebbe un contatore come questo. ma non capisco perché non funziona.
avete idea?
Grazie mille.
PHP:
<?php
// logging page hits
$dbfolder = $_SERVER["DOCUMENT_ROOT"]."/data/";
$dbname = $_SERVER["HTTP_HOST"]."_log.sq3";
// check if database file exists first
if(!file_exists($dbfolder.$dbname))
{
$logdb = new PDO("sqlite:".$dbfolder.$dbname);
$logdb->exec("CREATE TABLE hits(page VARCHAR(255) PRIMARY KEY, counter INTEGER)");
}
else
{
$logdb = new PDO("sqlite:".$dbfolder.$dbname);
}
$page = $_SERVER['REQUEST_URI'];
// check if page is already in the hits table
$statement = $logdb->query("SELECT counter FROM hits WHERE page='$page'");
$record = $statement->fetchAll();
// if a record is found
if(sizeof($record) != 0)
{
$counter = $record[0]['counter']++;
$logdb->exec("UPDATE hits SET counter=$counter WHERE page='$page'");
echo "Counter: ".$counter;
}
else
{
$logdb->exec("INSERT INTO hits(page, counter) VALUES ('$page', 1)");
echo "Counter: 1";
}
// close connection
$logdb = null;
?>
avete idea?
Grazie mille.