b Posted April 15, 2009 Share Posted April 15, 2009 Hi, I would like to put together a PHP Form that allows only one submission per IP address. Can anyone point me in the right direction for this...I know how to write a PHP form, interact with the database, etc. But I don't know what code to use that would involve IP address limitation... Thanks very much Link to comment https://forums.phpfreaks.com/topic/154141-php-form-with-ip-address-detection/ Share on other sites More sharing options...
MasterACE14 Posted April 15, 2009 Share Posted April 15, 2009 use... <?php $ip = $_SERVER["REMOTE_ADDR"]; ?> Link to comment https://forums.phpfreaks.com/topic/154141-php-form-with-ip-address-detection/#findComment-810270 Share on other sites More sharing options...
b Posted April 15, 2009 Author Share Posted April 15, 2009 Thanks for the suggestion...Here is what I have: A very simple registration form with some javascript validation: register.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <style type="text/css"> <!-- .style12 {font-family: Verdana, Arial, Helvetica, sans-serif} .style28 {color: #FF0000} .style29 {font-family: Arial, Helvetica, sans-serif} --> </style> </head> <body> <table width="90%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td> </td> </tr> <tr> <td> </td> </tr> <tr> <td><div align="justify"> <form action="submit.php" method="post" name="regform" id="regform" onsubmit="return Validate()"> <table width="75%" border="0" align="center" cellpadding="1" cellspacing="0"> <tr> <td bgcolor="#E54F1A"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF"> <tr> <td bgcolor="#FEF7F3"> </td> </tr> <tr> <td align="right" bgcolor="#FEF7F3"><span class="style28">*</span> Fields are Manditory </td> </tr> <tr> <td bgcolor="#FEF7F3"> </td> </tr> <tr> <td bgcolor="#FEF7F3"><table width="90%" height="320" border="0" align="center" cellpadding="3" cellspacing="0"> <tr bgcolor="#FEF7F3" class="style29"> <td>Full Name <span class="style28">*</span> </td> <td align="center">:</td> <td class="style29"><input name="name" type="text" id="name" size="21" /></td> </tr> <tr bgcolor="#FEF7F3" class="style29"> <td>E-Mail ID <span class="style28">*</span> </td> <td align="center">:</td> <td class="style29"><input name="email" type="text" id="email" size="21" /></td> </tr> <tr bgcolor="#FEF7F3" class="style29"> <td>1st <span class="style28">*</span> </td> <td align="center">:</td> <td class="style29"><input name="one" type="text" id="first" size="21" /></td> </tr> <tr bgcolor="#FEF7F3" class="style29"> <td>2nd <span class="style28">*</span> </td> <td align="center">:</td> <td class="style29"><input name="two" type="text" id="second" size="21" /></td> </tr> <tr bgcolor="#FEF7F3" class="style29"> <td>3rd <span class="style28">*</span> </td> <td align="center">:</td> <td class="style29"><input name="three" type="text" id="third" size="21" /></td> </tr> <tr bgcolor="#FEF7F3" class="style29"> <td>4th <span class="style28">*</span> </td> <td align="center">:</td> <td class="style29"><input name="four" type="text" id="fourth" size="21" /></td> </tr> <!--<tr bgcolor="#FEF7F3" class="style29"> <td>Address<span class="style28">*</span></td> <td align="center">:</td> <td class="style29"><textarea name="address" cols="16" rows="4" wrap="virtual" id="address"></textarea></td> </tr>--> <!--<tr bgcolor="#FEF7F3" class="style29"> <td>Phone Number <span class="style28">*</span> </td> <td align="center">:</td> <td class="style29"><input name="phone" type="text" id="phone" size="21" onkeyup="Only_Num(this.id)" /></td> </tr>--> <!--<tr bgcolor="#FEF7F3" class="style29"> <td>Mobile Number<span class="style28">*</span> </td> <td align="center">:</td> <td class="style29"><input name="mobile" type="text" id="mobile" size="21" onchange="javascript:LA()" onkeyup="Only_Num(this.id)" /></td> </tr>--> <tr bgcolor="#FEF7F3" class="style29"> <td height="97">Comments <span class="style28">*</span> </td> <td align="center">:</td> <td class="style29"><textarea name="comments" wrap="virtual" id="comments"></textarea></td> </tr> <tr align="center" bgcolor="#FEF7F3" class="style29"> <td colspan="3" class="style12"><input name="Submit" type="submit" class="style29" id="Submit" value="Submit" onclick="return chk()" /> <input name="Reset" type="reset" class="style29" value="Reset" /> <script>//global variable for error flag var errfound = false; //function to validate by length function ValidLength(item, len) { return (item.length >= len); } //function to validate an email address function ValidEmail(item) { if (!ValidLength(item, 5)) return false; if (item.indexOf ('@', 0) == -1) return false; return true; } // display an error alert function error(elem, text) { // abort if we already found an error if (errfound) return; window.alert(text); elem.select(); elem.focus(); errfound = true; } // main validation function function Validate() { errfound = false; if (!ValidLength(document.regform.name.value,6)) error(document.regform.name,"Name : minimum 6 characters"); if (!ValidLength(document.regform.address.value,10)) error(document.regform.address, "Invalid Address"); if (!ValidLength(document.regform.phone.value,10)) error(document.regform.phone,"Invalid phone number"); if (!ValidLength(document.regform.mobile.value,10)) error(document.regform.mobile,"Invalid mobile number"); if (!ValidEmail(document.regform.email.value)) error(document.regform.email, "Invalid Email Address"); if (!ValidLength(document.regform.comments.value,5)) error(document.regform.comments, "please Enter Your Comments"); return !errfound; /* true if there are no errors */ } </script><script language="JavaScript"> function Only_Num(id) { if(isNaN(document.getElementById(id).value)) { alert("Please Enter Numbers Only (0-9).."); document.getElementById(id).select(); document.getElementById(id).value="" document.getElementById(id).focus(); } return; } </script> </td> </tr> </table></td> </tr> <tr> <td bgcolor="#FEF7F3"> </td> </tr> <tr> <td bgcolor="#FEF7F3"> </td> </tr> </table></td> </tr> </table> </form> </div></td> </tr> <tr> <td> </td> </tr> <tr> <td> </td> </tr> </table> </body> </html> Submit.php <? if($_SERVER['REQUEST_METHOD']=="POST") { $mail_body.='<style type=text/css><!-- body,td,th {font-family: Arial, Helvetica, sans-serif; font-size: 12px;color: #666666;}--></style> <table width=60% border=0 align=center cellpadding=1 cellspacing=0> <tr> <td bgcolor=#E54F1A><table width=100% border=0 align=center cellpadding=3 cellspacing=0 bgcolor=#FFFFFF> <tr align=center bgcolor=#FEF7F3> <td colspan=3><strong>Feedback Form</strong></td> </tr> <tr bgcolor=#FEF7F3> <td width=26% >Full Name </td> <td width=3% align=center>:</td> <td width=71% >'.$_POST['name'].'</td> </tr> <tr bgcolor=#FEF7F3> <td>E-Mail ID</td> <td align=center>:</td> <td>'.$_POST['email'].'</td> </tr> <tr bgcolor=#FEF7F3> <td width=26% >1 </td> <td width=3% align=center>:</td> <td width=71% >'.$_POST['one'].'</td> </tr> <tr bgcolor=#FEF7F3> <td width=26% >2 </td> <td width=3% align=center>:</td> <td width=71% >'.$_POST['two'].'</td> </tr> <tr bgcolor=#FEF7F3> <td width=26% >3 </td> <td width=3% align=center>:</td> <td width=71% >'.$_POST['three'].'</td> </tr> <tr bgcolor=#FEF7F3> <td width=26% >4 </td> <td width=3% align=center>:</td> <td width=71% >'.$_POST['four'].'</td> </tr> <tr bgcolor=#FEF7F3> <td valign=top>Comments </td> <td align=center valign=top>:</td> <td>'.$_POST['comments'].'</td> </tr> </table> </td> </tr> </table>'; //echo $mail_body;exit; $mailto = '###'; $from='###'; $mailheader.="Return-Path: ".$from."\n"; $mailheader .= "From: ".$from."\n"; $mailheader .= 'MIME-Version: 1.0' . "\r\n"; $mailheader .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $mailheader.='From:'.$_POST['email']. "\r\n"; @mail($mailto,'Feedback Form',$mail_body,$mailheader); echo '<script language="javascript">window.location.href="thankyou.php";</script>'; } ?> In order to prevent multiple IP address entrants where would I put: <?php $ip = $_SERVER["REMOTE_ADDR"]; ?> Thanks! Link to comment https://forums.phpfreaks.com/topic/154141-php-form-with-ip-address-detection/#findComment-810308 Share on other sites More sharing options...
darkfreaks Posted April 15, 2009 Share Posted April 15, 2009 http://www.programmingtalk.com/showthread.php?t=22267 Link to comment https://forums.phpfreaks.com/topic/154141-php-form-with-ip-address-detection/#findComment-810311 Share on other sites More sharing options...
MasterACE14 Posted April 15, 2009 Share Posted April 15, 2009 log the IP address in a text file, and when the form is submitted run a check to see if that IP is already in the text file. Link to comment https://forums.phpfreaks.com/topic/154141-php-form-with-ip-address-detection/#findComment-810313 Share on other sites More sharing options...
b Posted April 15, 2009 Author Share Posted April 15, 2009 hate to sound too needy but I'm not sure how to do that... Link to comment https://forums.phpfreaks.com/topic/154141-php-form-with-ip-address-detection/#findComment-810366 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.