Jump to content

Limit one submission per ip?


Padgoi

Recommended Posts

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

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"; }

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']}'

     ");

}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.