ciao...tempo fa ho preso questo codice da non so dove, un contatore semplice per vedere gli accessi totali ad una pagine, l'ho riadattato e funzionava...poi l'ho rivisto ma non mi sembra di aver fatto modifiche sostanziali...fatto sta che ora non va più...
Codice PHP:
$countertype = "image"; // put "text" or "image", choose which counter style you want
$imagetype = ".gif"; // if using "image" above, put in the extension with the '.' of the img files. ie: ".gif",".jpg",".png"
$numofdigits = 4; // number of digits to show, if number of digits in hits is less than this, tack as many '0's on the front as needed
$percorso = "images/counter/"; // percorso per trovare le immagini cart/cart/
// configuration STOPS here
error_reporting(0); // because of some stupid e_notice
if(!file_exists('../counter/main.txt')){
$fp = fopen('../counter/main.txt','w');
fwrite($fp,'1');
}
$fp = fopen('../counter/main.txt','r');
$counta = fgets($fp);
$host = $HTTP_SERVER_VARS["HTTP_HOST"];
if($_SESSION["counter"] == "isset"){
}else{
$_SESSION["counter"] = "isset";
if(!strstr($HTTP_SERVER_VARS['HTTP_REFERER'], $host)) {
$counta++;
$fp = fopen('../counter/main.txt','w');
fwrite($fp,$counta);
}
}
$digits = array();
$digitlen = strlen($counta);
// this fills in the 0's before the number of hits, according to $numofdigits
$zerostofill = $numofdigits - $digitlen;
if ($zerostofill > 0) {
$countc = 1;
while ($countc <= $zerostofill) {
$countd .= 0;
$countc++;
}
$countc = $countd.$counta;
} else $countc = $counta;
if ($countertype != "image") echo $countc; //checks if the counter type is set to image, otherwise just print out the num of hits
else {
$countb = 0;
// and this finds the number of digits, and assigns each digit to part of an array, then gets the corresponding array[num], and prints it
while ($countb < strlen($countc)){
$digits[$countb] = substr($countc,$countb,'1');
$countb++;
}
$countb = 0;
while ($countb < strlen($countc)) {
echo '[img]' . $percorso . $digits[$countb] . $imagetype . '[/img]';
$countb++;
}
}