How to define maximum number of registrations allowed per IP within 24 hours

From aMember Pro Documentation
Revision as of 03:02, 3 November 2015 by Caesar (talk | contribs)
Jump to: navigation, search

Add this code to site.php file:

Am_Di::getInstance()->hook->add(Am_Event::VALIDATE_SAVED_FORM, function(Am_Event $e) {
    if ($e->getDi()->auth->getUserId()) return;

    $reg_max = 10;
    $reg_num = $e->getDi()->db->selectCell("SELECT COUNT(*) FROM ?_user WHERE remote_addr = ? AND added>?",
        $_SERVER['REMOTE_ADDR'], sqlTime('- 24 hours'));
    if ($reg_num > $reg_max) {
        $e->addError(___('Registration from you IP is temporary disabled'));