douwang9650 2013-05-13 19:40
浏览 48

在时间范围内查找数组中的记录

I'm adding some account-spamming security to my registration script.

The aim is for the script to reject the user from creating a new account if over 10 accounts in the database match their IP address, and these ten accounts were made in the last hour.

This would allow people in a library, for instance, to create their accounts, whilst also preventing people from spamming accounts in our database.

I have the following code, but how would I check if 10 or more accounts were made in the last 1 hour?

if($count_existscheck==1) {
    echo 'account already exists.';
    exit();
}
if($count_existscheck==0) {
    // begin check for IPs
    $ip = $_SERVER['REMOTE_ADDR'];
    $sql_ipcheck = "SELECT * FROM members WHERE ip='$ip'";
    $result_ipcheck = mysql_query($sql_ipcheck);
    $count_ipcheck = mysql_num_rows($result_ipcheck);

    // if count =10 or >10, check if they were in the last hour
    if($count_ipcheck>9) {
        $row_ipcheck = mysql_fetch_assoc($result_ipcheck);
    }
}
  • 写回答

1条回答 默认 最新

  • dongmo9996 2013-05-14 00:46
    关注

    Try this:

    $onehourbefore = strtotime('-1 hour');
    $sql_ipcheck = "SELECT * FROM members 
             WHERE ip = '$ip' AND lastregistration > $onehourbefore;
    $result_ipcheck = mysql_query($sql_ipcheck);
    
    if(mysql_num_rows($result_ipcheck)>=10) echo 'Access Denied';
    

    You should have a column in tha members table called 'lastregistration' where you store the time of the registrations now in Unix timestamp.

    (And you should check the time of your mysql server and the time of your webserver. And you should use mysqli_query() not mysql_query() ... )

    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法