괜찮습니다. 나는 3 개의 필드가있는이 콘테스트 등록 양식을 mySQL DB에 삽입합니다 ... 이메일로 보내는 것뿐입니다. 사용자의 현재 IP에 대한 양식을 점검하고 존재하는 경우 제출을 허용하지 않는이 코드를 추가합니다.테이블에있는 IP 주소를 확인하십시오 - mySQL PHP
이것은 현재 오류없이 실행되고있는 것처럼 보입니다.하지만 동일한 IP의 여러 제출을 허용합니다. 뭐가 잘못 나온거야? 아래
FULL CODE :
<?php //include the connection file
require_once('connection.php');
function sanitize($value, $type)
{
$value = (!get_magic_quotes_gpc()) ? addslashes($value) : $value;
switch ($type) {
case "text":
$value = ($value != "") ? "'" . $value . "'" : "NULL";
break;
case "long":
case "int":
$value = ($value != "") ? intval($value) : "NULL";
break;
case "double":
$value = ($value != "") ? "'" . doubleval($value) . "'" : "NULL";
break;
case "date":
$value = ($value != "") ? "'" . $value . "'" : "NULL";
break;
}
return $value;
}
//save the data on the DB and send the email
if(isset($_POST['action']) && $_POST['action'] == 'submitform')
{
//recieve the variables
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$ip = gethostbyname($_SERVER['REMOTE_ADDR']);
mysql_select_db($database, $connection);
$QUERY = "SELECT COUNT(IP) AS `count` FROM `contest` WHERE IP = 'value'";
$RESULT = mysql_query($QUERY) or die(mysql_error());
// Read the firs row
$row = mysql_fetch_assoc($RESULT);
// Check how many rows MySQL counted
if($row['count'] > 0) {
echo "value already exists";
}
else {
//save the data on the DB
mysql_select_db($database, $connection);
$insert_query = sprintf("INSERT INTO contest (First_Name, Last_Name, Email_Address, Date, ip) VALUES (%s, %s, %s, NOW(), %s)",
sanitize($firstname, "text"),
sanitize($lastname, "text"),
sanitize($email, "text"),
sanitize($ip, "text"));
$result = mysql_query($insert_query, $connection) or die(mysql_error());
if($result)
{
//send the email
$to = "EMAIL ADDY";
$subject = "SUBJECT LINE";
//headers and subject
$headers = "MIME-Version: 1.0rn";
$headers .= "Content-type: text/html; charset=iso-8859-1rn";
$headers .= "From: ".$firstname." <".$email.">rn";
$body = "New contact
";
$body .= "First Name: ".$firstname."
";
$body .= "Last Name: ".$lastname."
";
$body .= "Email: ".$email."
";
$body .= "IP: ".$ip."
";
mail($to, $subject, $body, $headers);
//ok message
header ('Location: thanks.html');
exit();
}
}
}
?>
어떤 종류의 문제가 있습니까? (그리고 그 줄에는 왜이 작은 따옴표가 붙어 있습니까?) – johannes
inet MySQL 함수를 사용하는 것도 중요합니다. [이것을보십시오] (http://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html#function_inet-aton). –
그건 좋은 생각이 아닐 수도 있습니다. 나는 대학 도시에 산다. 캠퍼스에 거주하는 모든 학생들은 공용 IP 주소 하나를 공유합니다. –