Padgoi Posted February 21, 2008 Share Posted February 21, 2008 Ok, so right now I have this code: $sql= htmlspecialchars ("INSERT INTO Ratings (username, profile, registration, ip) VALUES ('$_POST[username]','$_POST[prof]','$_POST[registration]','$_SERVER[REMOTE_ADDR]')"); As you can see, the last column is logging ip addresses for everyone who submits information. I need an if statement or something that will limit one submission per ip so that if someone tries to make 2 submissions from the same ip, they won't be able to. Can anyone help me with this? Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/92240-limit-one-submission-per-ip/ Share on other sites More sharing options...
axiom82 Posted February 21, 2008 Share Posted February 21, 2008 Make the IP field a UNIQUE index...that's the lazy way. Link to comment https://forums.phpfreaks.com/topic/92240-limit-one-submission-per-ip/#findComment-472541 Share on other sites More sharing options...
beansandsausages Posted February 21, 2008 Share Posted February 21, 2008 Try : $ip = $_SERVER[REMOTE_ADDR]; $check = mysql_query("SELECT * FROM Ratings WHERE ip = '$ip'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if($info['ip'] == $_SERVER[REMOTE_ADDR]) { echo " No poste "; } else { echo " okay to post"; } Link to comment https://forums.phpfreaks.com/topic/92240-limit-one-submission-per-ip/#findComment-472542 Share on other sites More sharing options...
bpops Posted February 21, 2008 Share Posted February 21, 2008 <?php $query = "SELECT * from Ratings where ip = '$_SERVER[REMOTE_ADDR]'"; $result = mysql_query($query); $n_results = mysql_num_rows($result); if($n_results){ // already submitted. throw error }else{ // run your sql injection } ?> Link to comment https://forums.phpfreaks.com/topic/92240-limit-one-submission-per-ip/#findComment-472543 Share on other sites More sharing options...
axiom82 Posted February 21, 2008 Share Posted February 21, 2008 Or you could do this... if (mysql_num_rows (mysql_query ("SELECT * FROM `Ratings` WHERE `ip` = '{$_SERVER['REMOTE_ADDR']}'")) == 0){ mysql_query (" INSERT INTO `Ratings` SET `username` = '{$_POST['username']}', `profile` = '{$_POST['prof']}', `registration` = '{$_POST['registration']}', `ip` = '{$_SERVER['REMOTE_ADDR']}' "); } Link to comment https://forums.phpfreaks.com/topic/92240-limit-one-submission-per-ip/#findComment-472547 Share on other sites More sharing options...
Padgoi Posted February 21, 2008 Author Share Posted February 21, 2008 Thanks fellas, got it working now! Link to comment https://forums.phpfreaks.com/topic/92240-limit-one-submission-per-ip/#findComment-472548 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.