0

I'm using Drupal 6.19.I need two things to be done.First thing, I want to disable multiple user registrations from the same IP.The Second thing is ,I want to allow only 3 user to register at a time. Anyone know this how to do in Drupal6.19?

Please help me to do this.

  • could you explain the second requirement a bit more in detail. what do you mean by 2 or 3 registration at a time – Mohammed Shameem Jan 23 '13 at 9:13
  • @MohammedShameem.Thanks for your response.I edited my question.The second requirement is how to allow three users to register at same time in my site? – Ranjani Jan 23 '13 at 9:20
  • what do you mean by three users? three users with the same ID? That part is not clear to me yet – Mohammed Shameem Jan 23 '13 at 9:24
  • @mohammed Shahmeem.Only three anonymous users can register at same time.Hope this gives clear explanation. – Ranjani Jan 23 '13 at 9:28
2

You may find the problem there is that Drupal doesn't store the IP address of the user during normal core registration process.

Assuming you can hook in and store that IP address for later lookup, you could then validate that ip address count for the user with something like:

/**
 * Implements hook_form_FORM_ID_alter
 */
function mymodule_form_user_register_alter(&$form, &$form_state) {
  $form['#validate'][] = 'mymodule_user_register_validate';
}

/**
 * hook_form_user_register_alter validation callback
 */
function mymodule_user_register_validate($form, &$form_state) {
  $account = (object) $form_state['values'];
  $ip_address = ip_address(); // api call
  // do something to look up ip_address on registered user..
  // for example: 
  $count = db_query("SELECT count(uid) FROM {user_ip} WHERE ip = :ip", array(':ip' => $ip_address))->fetchField();
  if($count > 3){
    $error = t('Sorry, too many registrations.');
    form_set_error('name', $error);
  }
}
2

It`s not a good idea to block multiple user registrations in this way, it might be possible that some users use the same ip (such as proxies etc.) But anyway you can use User IP Log module with Rules module, to block multiple user registrations. something like this:

  1. Install User Ip Log module and rules module
  2. Enable PHP Filter module
  3. Create a rule ,use your custom php code to check the users Ip log and block theme with your custom conditions.

* Note that your conditions should be date-realted because Internet Provider Services, assign this IPs to others too.

  • The problem with that approach is that IP Log module only implements hook_user_login so a user could register as many times as they liked, as long as they didn't login. You would need to extend it to use hook_user_insert when storing the ip address, then it would work well with the solution I suggested as the table lookup. – David Thomas Jan 23 '13 at 9:42
  • yes @David, it should be extended to hook_user_insert. – Reza Shadman Jan 23 '13 at 9:58
0

I blocked multiple user registration from same IP by customizing the user core module , in the user table I added a column to store the IP address of the user registering. When the function user_register_submit calls, I will check if the IP of the user who is registering is already stored in that column or not.

And when the function user_save executes i will save the IP of the user.

Thanks for the friends who are all posted their answers and comments.Thanks for your support!

  • In case of dynamic ip allocation the above help gives problem. as it sometimes blocks new registrations also. – user34532 Jul 28 '14 at 6:12
  • @pretty (the original poster), would you mind sharing with us how you accomplished this? I.e a step by step guide. I think this would be very helpful for others that come across this thread. I know I would love to implement this on my site. – AmericanNinja Aug 13 '14 at 14:30
  • No need to hack core to do this. – stefgosselin Nov 2 '15 at 16:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.