PDA

View Full Version : Script: Counter Grafico in PHP


fank
11-10-2002, 02:03
FanKounter
Contatore di accessi che include semplici report statistici.
Scritto in PHP4 da fanatiko e utilizzabile senza condizioni/restrizioni.

CARATTERISTICHE (alcune)
Doppia modalità: grafico/testo.
Altamente configurabile e personalizzabile.

REQUISITI
(i) Hosting su WEB Server che supporti PHP4.
(ii) Librerie GD supportate da PHP.

ESEMPIO
Guarda il mio avatar (si adatta ad ogni immagine PNG).

Se sei interessato, per approfondimenti/istruzioni d'uso:
o vai ĺ (http://utenti.lycos.it/profitterol/fankounter/index.htm) (*),
o leggi qua (http://utenti.lycos.it/profitterol/fankounter/readme.txt) (*),
o scarica qui (http://utenti.lycos.it/profitterol/fankounter/fkounter.zip) (*).
_____
(*) tripod/lycos permettendo!

Segue codice del modulo principale, anche <u>standalone</u>...

fanatiko

fank
11-10-2002, 03:20
&lt;?php

########## CONFIGURAZIONE

$start_count=0;
$img_base=&quot;counter.png&quot;;
$back_color=array(&quot;R&quot;=&gt;0,&quot;G&quot;=&gt;0,&quot;B&quot;=&gt;0);
$text_color=array(&quot;R&quot;=&gt;255,&quot;G&quot;=&gt;255,&quot;B&quot;=&gt;255);
$store_file=&quot;counter.dat&quot;;
$stats_file=&quot;stats.dat&quot;;
$ref_paths=array();

########## PARAMETRO IN INPUT (opzionale)

$mode=($mode==&quot;text&quot;)?$mode:&quot;graphic&quot;;

########## SEZIONE OPERATIVA

function manstats($safemode){
global $store_file,$stats_file,$start_count;
global $REMOTE_ADDR,$HTTP_REFERER,$HTTP_USER_AGENT;
$return_count=0;

if(file_exists($store_file)==TRUE){
if(($stats_id=fopen($stats_file,&quot;a&quot;))!==FALSE){
if(flock($stats_id,LOCK_EX)!=FALSE){
if(($store_id=fopen($store_file,&quot;r&quot;))!==FALSE){
$return_count=fgets($store_id,filesize($store_file )+1);
fclose($store_id);
if($return_count!==FALSE){
settype($return_count,&quot;integer&quot;);
++$return_count;
if(!$safemode){
if(($store_id=fopen($store_file,&quot;w&quot;))!==FALSE){
if(fwrite($store_id,$return_count)==strlen($return _count))
fwrite($stats_id,$return_count.&quot;,&quot;.date(&quot;d-m-Y&quot;).&quot;,&quot;.date(&quot;H:i:s&quot;).&quot;,&quot;.$REMOTE_ADDR.&quot;,&quot;.$HTTP_U SER_AGENT.&quot;,&quot;.$HTTP_REFERER.&quot;\n&quot;);
fclose($store_id);
}
}
}
}
unset($store_id);
flock($stats_id,LOCK_UN);
}
fclose($stats_id);
}
unset($stats_id);
}
elseif(file_exists($store_file)==FALSE){
$return_count=$start_count;
$store_id=fopen($store_file,&quot;w&quot;);
fwrite($store_id,$return_count);
fclose($store_id);
unset($store_id);
}

return $return_count;
unset($safemode,$return_count);
}

if((count($ref_paths)==0)||(in_array(((strpos($HTT P_REFERER,&quot;?&quot;)===FALSE)?$HTTP_REFERER:substr($HTTP _REFERER,0,strpos($HTTP_REFERER,&quot;?&quot;))),$ref_paths) ))
$new_count=manstats(0);
else
$new_count=manstats(1);

if(($mode==&quot;graphic&quot;)&amp;&amp;(function_exists(&quot;imagepng&quot; ))){
if(($img_base==&quot;&quot;)||(!($myimg=imagecreatefrompng($ img_base))))
$myimg=imagecreate(60,15);
$basey=imagesy($myimg)-15;
$basey=($basey&lt;0)?0:$basey;
$bgcolor=imagecolorallocate($myimg,$back_color[R], $back_color[G],$back_color[B]);
imagefilledrectangle($myimg,0,$basey,59,$basey+14, $bgcolor);
$txtcolor=imagecolorallocate($myimg,$text_color[R] ,$text_color[G],$text_color[B]);
imagestring($myimg,3,3,$basey+1,str_pad($new_count ,8,&quot;0&quot;,STR_PAD_LEFT),$txtcolor);
header(&quot;Content-type: image/png&quot;);
imagepng($myimg);
imagedestroy($myimg);
unset($myimg,$txtcolor,$bgcolor,$basey);
}
else
echo&quot;
&lt;HTML&gt;
&lt;BODY BGCOLOR='#&quot;.dechex($back_color[R]).dechex($back_co lor[G]).dechex($back_color[B]).&quot;' TEXT='#&quot;.dechex($text_color[R]).dechex($text_color [G]).dechex($text_color[B]).&quot;'&gt;
&lt;DIV ALIGN='center' STYLE='font-family:Arial;font-size:9pt;font-weight:bold'&gt;
&quot;.str_pad($new_count,8,&quot;0&quot;,STR_PAD_LEFT).&quot;
&lt;/DIV&gt;
&lt;/BODY&gt;
&lt;/HTML&gt;
&quot;;

unset($new_count);
unset($start_count,$img_base,$back_color,$text_col or,$store_file,$stats_file,$ref_paths);

?&gt;