Knowledge Base Nr: 00119 counter.txt - http://www.swe-kaiser.de
Downloads:
grafischer counter in PHP
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Dummy</title>
</head>
<body>
<p>der countertest - start</p>
<?
#counter auslesen und incrementieren
$fp = fopen("./cgi-bin/counter.cnt", "rt");
flock($fp, 1); #LOCK_SH
$count = fread($fp, 100);
flock($fp, 3); #LOCK_UN
fclose($fp);
trim($count);
$count = $count + 1;
$fp = fopen("./cgi-bin/counter.cnt", "wt");
flock($fp, 2); #LOCK_EX
fwrite($fp,"$count");
flock($fp, 3); #LOCK_UN
fclose($fp);
#ausgeben des counters als gifs
$gif_dir = "/kaiserreich/images/k_images/numbers/";
$gifs = array("0.jpg","1.jpg","2.jpg","3.jpg","4.jpg","5.jpg","6.jpg","7.jpg","8.jpg","9.jpg");
$tnuoc = 1000000.0 + $count; #für anzeige auf anzahl der stellen+1 erweitern z.b. 1000000.0;
$digit0 = substr ((string)$tnuoc,1,1);
$digit1 = substr ((string)$tnuoc,2,1);
$digit2 = substr ((string)$tnuoc,3,1);
$digit3 = substr ((string)$tnuoc,4,1);
$digit4 = substr ((string)$tnuoc,5,1);
$digit5 = substr ((string)$tnuoc,6,1);
$gif0 = "$gif_dir$gifs[$digit0]";
$gif1 = "$gif_dir$gifs[$digit1]";
$gif2 = "$gif_dir$gifs[$digit2]";
$gif3 = "$gif_dir$gifs[$digit3]";
$gif4 = "$gif_dir$gifs[$digit4]";
$gif5 = "$gif_dir$gifs[$digit5]";
$counterstring = "\n<img src=$gif0><img src=$gif1><img src=$gif2><img src=$gif3><img src=$gif4><img src=$gif5>\n";
echo($counterstring);
?>
<p>das wars.</p>
</body>
</html>