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

Simple Counter

A simple counter.



<?php
$padding =6;
$fpt = "counter.txt";
$lock_ip =0;
$ip_lock_timeout =30;
$fpt_ip = "ip.txt";
function checkIP($rem_addr) {
    global $fpt_ip,$ip_lock_timeout;
    $ip_array = file($fpt_ip);
    $reload_dat = fopen($fpt_ip,"w");
    $this_time = time();
    for ($i=0; $i<sizeof($ip_array); $i++) {
        list($ip_addr,$time_stamp) = split("\|",$ip_array[$i]);
        if ($this_time < ($time_stamp+60*$ip_lock_timeout)) {
            if ($ip_addr == $rem_addr) {
                $found=1;
            }
            else {
                fwrite($reload_dat,"$ip_addr|$time_stamp");
            }
        }
    }
    fwrite($reload_dat,"$rem_addr|$this_time\n");
    fclose($reload_dat);
    return ($found==1) ? 1 : 0;
    }
    if (!file_exists($fpt)) {
        $count_dat = fopen($fpt,"w+");
        $count = 1;
        fwrite($count_dat,$count);
        fclose($count_dat);
    }
    else {
        $line = file($fpt);
        $count = $line[0];
    if ($lock_ip==0 || ($lock_ip==1 && checkIP($REMOTE_ADDR)==0)) {
        $count_dat = fopen($fpt,"r+");
        $count++;
        fwrite($count_dat,$count);
        fclose($count_dat);
    }
}
echo sprintf ("%0"."$padding"."d",$count);
?>


Download code...


Print this page


 

Inizio pagina

risorse per webmaster