Morpheusweb.it - Risorse per webmaster: script, ASP.NET, C#, Visual Basic .Net, tutorial, asp, javascript, css, php, html, java, ADO, VBScript, forms, frames, Active Server Pages, Dynamic HTML, database, gratis per webmaster e webdesigner

Access Graph Counter

Simple graphic counter, particularity is that the images are not files but are produced on the fly. It saves the accesses on a text file.



<?php
$COUNT_FILE = "count_data.txt";
$NB_DIGITS = 8;
header("content-Type: image/gif");
$img = ImageCreate(9 * $NB_DIGITS + 1, 17);
$bg_color = ImageColorAllocate($img, 0 ,0, 0);
$text_color = ImageColorAllocate($img, 255, 255, 255);
if (! file_exists($COUNT_FILE)) {
    $txt = "Can't find file, check '\$file' var...<BR>";
} else {
    $fp = fopen("$COUNT_FILE", "r+");
    flock($fp, 1);
    $count = fgets($fp, 4096);
    $count += 1;
    fseek($fp,0);
    fputs($fp, $count);
    flock($fp, 3);
    fclose($fp);
    chop($count);
    $nb_digits = max(strlen($count), $NB_DIGITS);
    $txt = substr("0000000000".$count, -$nb_digits);
}
ImageString($img,5,1,0,$txt,$text_color);
ImageGif($img);
ImageDestroy($img);
?>


Download code...


Print this page


 

Inizio pagina

risorse per webmaster