# Limit Sign-Ups per IP Address

> Allows only a few new accounts per IP address per day, which stops bots and people from creating piles of accounts.

- Type: PHP
- Runs: Run everywhere
- Category: [Users](https://wpide.com/library/category/users/)
- Tags: registration, spam, security
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/registration-limit-per-ip/

## Code

```php
// Accounts allowed per IP address in the window below.
$wpide_reg_ip_limit  = 3;
$wpide_reg_ip_window = DAY_IN_SECONDS;

$wpide_reg_ip_key = function () {
    $ip = isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : '';

    return 'wpide_reg_ip_' . md5( $ip );
};

add_filter( 'registration_errors', function ( $errors ) use ( $wpide_reg_ip_limit, $wpide_reg_ip_key ) {
    if ( (int) get_transient( $wpide_reg_ip_key() ) >= $wpide_reg_ip_limit ) {
        $errors->add( 'wpide_reg_ip', '<strong>Error:</strong> Too many accounts have been created from your network today. Please try again tomorrow.' );
    }

    return $errors;
}, 5 );

add_action( 'register_new_user', function () use ( $wpide_reg_ip_window, $wpide_reg_ip_key ) {
    $key = $wpide_reg_ip_key();
    set_transient( $key, (int) get_transient( $key ) + 1, $wpide_reg_ip_window );
} );
```

## Notes

Behind a proxy or CDN make sure REMOTE_ADDR holds the visitor's real IP, or everyone shares one limit.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Limit Sign-Ups per IP Address" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
