php - Find records in array in time range -
i'm adding account-spamming security registration script.
the aim script reject user creating new account if on 10 accounts in database match ip address, , these ten accounts made in last hour.
this allow people in library, instance, create accounts, whilst preventing people spamming accounts in our database.
i have following code, how check if 10 or more accounts made in last 1 hour?
if($count_existscheck==1) { echo 'account exists.'; exit(); } if($count_existscheck==0) { // begin check ips $ip = $_server['remote_addr']; $sql_ipcheck = "select * members ip='$ip'"; $result_ipcheck = mysql_query($sql_ipcheck); $count_ipcheck = mysql_num_rows($result_ipcheck); // if count =10 or >10, check if in last hour if($count_ipcheck>9) { $row_ipcheck = mysql_fetch_assoc($result_ipcheck); } }
try this:
$onehourbefore = strtotime('-1 hour'); $sql_ipcheck = "select * members ip = '$ip' , lastregistration > $onehourbefore; $result_ipcheck = mysql_query($sql_ipcheck); if(mysql_num_rows($result_ipcheck)>=10) echo 'access denied';
you should have column in tha members table called 'lastregistration' store time of registrations in unix timestamp.
(and should check time of mysql server , time of webserver. , should use mysqli_query() not mysql_query() ... )
Comments
Post a Comment