把记录记到数据库中,包括IP和时间,然后由同一个IP时判断时间,就是了。

解决方案 »

  1.   

    同时记录ip和时间就在判断一下就ok了
      

  2.   

    数据表结构:
    mysql> desc ipLogTmp;
    +--------+------------------+------+-----+---------+-------+
    | Field  | Type             | Null | Key | Default | Extra |
    +--------+------------------+------+-----+---------+-------+
    | vcIp   | varchar(16)      |      |     |         |       |
    | inTime | int(10) unsigned |      |     | 0       |       |
    +--------+------------------+------+-----+---------+-------+<?
    /*
     * 检验同一ip登陆时间
     * $tmlap 要求登陆时间间隔
     * return: 如果是正常登陆返回true,如果在$tmlap之内重复登陆返回false
     */
    function checkMachine($tmlap="6")
    {
    $IP = getenv("REMOTE_ADDR");
    $tm = time();
    $query = "Select inTime from ipLogTmp where vcIP='$IP' order by inTime desc";
    $res = mysql_query($query);
    while($row = mysql_fetch_array($res)) {
    if(($tm-$row[inTime])<$tmlap) return false;
    }
    $query = "Insert into ipLogTmp values('$IP',$tm)";
    mysql_query($query);
    return true;
    }
    ?>