Difference between revisions of "How to define maximum number of registrations allowed per IP within 24 hours"

From aMember Pro Documentation
Jump to: navigation, search
Line 2: Line 2:
 
<source>
 
<source>
 
<?php
 
<?php
Am_Di::getInstance()->hook->add(Am_Event::LOAD_SIGNUP_FORM, function(Am_Event $e) {
+
Am_Di::getInstance()->hook->add(Am_Event::VALIDATE_SAVED_FORM, function(Am_Event $e) {
 +
    if ($e->getDi()->auth->getUserId()) return;
 +
 
 
     $reg_max = 10;
 
     $reg_max = 10;
 
     $reg_num = $e->getDi()->db->selectCell("SELECT COUNT(*) FROM ?_user WHERE remote_addr = ? AND added>?",
 
     $reg_num = $e->getDi()->db->selectCell("SELECT COUNT(*) FROM ?_user WHERE remote_addr = ? AND added>?",
 
         $_SERVER['REMOTE_ADDR'], sqlTime('- 24 hours'));
 
         $_SERVER['REMOTE_ADDR'], sqlTime('- 24 hours'));
 
     if ($reg_num > $reg_max) {
 
     if ($reg_num > $reg_max) {
         throw new Am_Exception_InputError(___('Registration from you IP is temporary disabled'));
+
         $e->addError(___('Registration from you IP is temporary disabled'));
 
     }
 
     }
 
});
 
});
 
 
</source>
 
</source>

Revision as of 03:02, 3 November 2015

Add this code to site.php file:

<?php
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'));
    }
});