Counter, IP-Sperre nach ner bestimmten Zeit aufheben...

  • hey dudes!

    ich hab auf meiner Seite jetzt mal nen Counter laufen, mit IP-Sperre.
    Der legt im angegebenen Pfad eine Datei mit dem Namen ip_log,
    eine mit dem Namen u_hits.txt und auf dem PC des Users ein Cookie an.
    Jetzt würde ich das Ganze gerne so haben, dass der Counter die gespeicherte IP
    und eventuell auch das (oder den?) Cookie nach ner bestimmten Zeit (3h) löscht,
    so dass, wenn der User wieder kommt, der Counter wierder weiter zählt.

    Kennt sich einer so aus, dass er mir sagen kann,
    wie ich das verwirkliche?

    Das hier ist der Code vom Counter:


    [php:1:3fbbebdf60]
    <?php
    //------------
    //Just a plain unique hits script.
    //Tracks by IP and cookie.
    //FULLY commented.
    //------------


    //This is explained in the readme(just a little)
    //I recommend you leave it the same unless you
    //know what your doing.
    $l_dir="";

    //The following shouldnt need to be modded at all. but go ahead anyway.

    //[Functions]
    function add_ip($ip,$log,$l_dir) {
    $fp=fopen($l_dir."ip_log",w);
    if(fwrite($fp,$log."\n".$ip)) {
    //ip added
    } else {
    die("ERROR! IP NOT ADDED");
    }
    fclose($fp);
    }

    //[Setting string things.]
    $ip=$_SERVER['REMOTE_ADDR'];//The users ip.
    $ips=file_get_contents($l_dir."p_log");//The list of ips.
    $hts=file_get_contents($l_dir."u_hits.txt");//how many hits.
    $cookie=$_COOKIE['unique_cookie'];//My speshul cookie name.

    //[Actuall counter functions]
    if(strstr($ips,$ip)) {//If ip is in the log.
    if($cookie) {
    //IP and cookie. My work here is done.
    } else {//Ip but no cookie.
    //He cleared the cookie, set it again.
    setcookie("unique_cookie",true);//Set a cookie.
    }
    } else {
    if($cookie) {
    //Changed his ip but kept the cookie, add his new ip.
    add_ip($ip,$ips,$l_dir);//Add the ip
    } else {
    //Add an ip, cookie, and one to the count.
    setcookie("unique_cookie",true);//Set a cookie.
    add_ip($ip,$ips,$l_dir);//Add the ip.
    $fp2=fopen($l_dir."u_hits.txt",w);//open the file
    fwrite($fp2,$hts+1);//add one to the count
    fclose($fp2);//close the file
    }
    }
    ?>
    [/php:1:3fbbebdf60]


    DANKE!!!!!!!!

  • also das mit dem cookie ist einfach.

    http://de.php.net/manual/en/function.setcookie.php

    setcookie('unique_cookie',true, time()+10800);

    dann gilt es nur 3 Stunden (10800 Sekunden )

    mit der datein, das würde ich den so lösen, das du jeweils IP und timestam speicherst im CSV format oder so und dann die datei in eien array lädst wobei du dann einfach immer alles aus der array löscht was zu alt ist, bevor du vergleichst. Dazu dann wieder alles abspeichern.

    wenn es nicht zu viel speicher kostet, kann man es auch anders machen.

    Ich würde da dann aber schon eien DB entfehlen spart zeit und arbeit.