基于有有效期的IP限制用户注册插件?

时间:2015-03-21 作者:Kreation

与大多数垃圾邮件发送者/垃圾邮件管理器插件不同,这些插件可以阻止已知垃圾邮件ip和电子邮件域列表中的注册,我需要阻止恶意用户尝试从同一ip地址注册多个帐户。他们的意图可能是在其他账户被禁止后骚扰评论中的人,或者他们可能试图用我的提交表单玩游戏,提交重复的结果,试图破坏输出的完整性。

有没有办法限制ip地址在给定时间段内注册帐户?由于IP地址发生了变化,我希望仍然允许一些无辜的人注册,他们可能最终拥有以前被阻止的IP。

2 个回复
最合适的回答,由SO网友:Adam 整理而成

尽管这种方法可能存在缺陷,因为它可以使用代理进行旁路,但这里有一种过于简单(尚未测试)的方法you would need to improve upon 但是会给你实现你想要的目标打下基础。

在我看来,这个过程:

筛选上的用户注册pre_user_loginpre_user_nicename 钩住数据库,查看IP是否存在于时间限制的黑名单中。如果IP存在于范围内,则使用自定义错误消息拒绝注册。如果IP不存在于范围内,则将IP添加到时间限制的黑名单中。每次注册尝试时,请清洗并重复此操作。示例:

function filter_user_registration_ip($user_nicename) {

    $ip        = $_SERVER[\'REMOTE_ADDR\'];                    //get current IP address
    $time      = time();                                     //get current timestamp
    $blacklist = get_option(\'user_ip_blacklist\') ?: array(); //get IP blacklist

    /*
     * If IP is an array key found on the resulting $blacklist array
     * run a differential of the 
     * 
     */
    if ( array_key_exists($ip, $blacklist) ) {

        /*
         * Find the difference between the current timestamp and the timestamp at which
         * the IP was stored in the database converted into hours.
         */
        $diff_in_hours = ($time - $blacklist[$ip]) / 60 / 60;


        if ( $diff_in_hours < 24 ) {

            /*
             * If the difference is less than 24 hours, block the registration attempt
             * and do not reset or overwrite the timestamp already stored against the
             * current IP address.
             */
            wp_die(\'Your IP is temporarily blocked from registering an account\');
        }

    }    

    /*
     * If the IP address does not exist, add it to the array of blacklisted IPs with
     * the current timestamp (now).
     *
     * Or if the IP address exists but is greater than 24 hours in difference between
     * the original stored timestamp and the current timestamp, add it to the array
     * of blacklisted IPs.
     */
    $blacklist[$ip] = $time;
    update_option(\'user_ip_blacklist\', $blacklist);      

    return $user_nicename;

}

add_filter(\'pre_user_nicename\', \'filter_user_registration_ip\', 10, 1);
备注:

上述代码为untestedmay contain errors.

SO网友:wordpress

更好的解决方案是不禁止Wordpress中的IP,但如果您有WHM的root访问权限,那么您可以从您的服务器中完全禁止他们的IP。这才是问题的真正解决办法。

此外,IP地址通常不会更改。然而,一个人可以通过另一个internet连接、代理服务器或其他方式使用备用IP。然而,这对他们来说仍然是一件痛苦的事,因为一旦你禁止了他们的家庭IP,他们唯一真正的解决办法就是让他们的ISP更改他们的IP,其中许多ISP将不愿意这样做,或者干脆拒绝这个请求。

如果您无权访问WHM或服务器的根目录,那么您仍然可以通过将其添加到来禁止其IP。htaccess文件如下:

order allow,deny
deny from 123.45.67.89
allow from all

结束

相关推荐

具有序列化的自定义元值的GET_USERS

我正在尝试使用get_users 选择只有特定元值的用户。在这种情况下,元键是extraInfo 但这些值位于序列化数组中。我可以这样把用户拉出来吗?这就是我一直在尝试的,但运气不佳:$meta_key = \'extraInfo[zip]\'; $meta_value = $zip; $query = get_users(\'meta_key=\'.$meta_key.\'&meta_value=\'.$meta_value);