ho scaricato il seguente script da php.html.it
Codice PHP:
<?php
/***************************************************************************
* count.php
* -------------------
* begin : Tuesday, Feb 28, 2006
* owner : AtomicOxide.co.uk - Dave
* email : [email]dave@atomic-network.co.uk[/email]
*
*
***************************************************************************/
/***************************************************************************
*
* This program is a free script; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
***************************************************************************/
// Set varibles
$cookie_ip = $_COOKIE['client_ip'];
$file = "count.txt"; // File to hold the views in.
$line = file($file);
// See if the cookie is already set.
if(!$cookie_ip) {
// If not; set the cookie.
setcookie("client_ip", $_SERVER['REMOTE_ADDR'] , time()+360000);
$line[0]++; // Increase value of file by one...
// Open the file for writing
$open = fopen($file, "w+");
// Write to File.
fputs($open, "$line[0]");
fclose($open);
}
// See if the cookie IP matches the users IP
elseif($cookie_ip != $_SERVER['REMOTE_ADDR']){
$line[0]++;
$open = fopen($file, "w+");
fputs($open, "$line[0]");
fclose($open);
}
$count = $line[0]++;
// Now Display Results.
?>
<center>Unique Page Views: [b]<?php echo $count; ?>[/b] times
Made by [url="http://atomicoxide.co.uk"]AtomicOxide.co.uk[/url]
dovrei far conteggiare la visita nel database al posto del file count.txt:
Codice PHP:
$newhits = ($row_p['hits'] * 1) + 1;
$update = "update count set hits =" . $newhits . " where id = ". $row_p['id'];
mysql_query($update,$myconn) or die(mysql_error());
cosa devo aggiungere per fare ciò?
grazie