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

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.