php - is it possible creation of duplicate ip in this code? -
i have popup rotator count unic user's ip per day(no duplicate ip allowed user in same date)
$userip = mysql_real_escape_string($_server['remote_addr']); $date = date('y-m-d'); $result = mysql_query("select `ip` `popupip` ip = '$userip' , userid = $secid , date='$date'"); $num = mysql_num_rows($result); if ($num > 0) { // **it duplicate not insert in popupip table** }else{ // **it not duplicate ip insert in popupip table** }
above code example.i know full code.
but when phpmyadmin popupip
table there few duplicate ip user (the exact same ip address user on same date)
how possible?
extra information: in popupip
userid
int(11) , date
"date type 2014-05-30" , ip
varchar. page may opens "as fast possible @ same time" popup pages. there relation between openning page fast @ same time user , duplicate ip creation? there bug in mysql? (maybe big bug!!!!)
yes, possible. it's classical case of race condition.
the quick explanation:
there chance 2 requests simultaneously pass first check, $num == 0
, both insert new row.
to eliminate need create unique
constraint covers (user_id, ip, date)
columns
the long explanation:
Comments
Post a Comment