2013-08-08 3 views
0

나는 허니팟 입력 필드를 포함하고있는 간단한 문의 양식을 가지고 있습니다. 필드가 채워지면 양식을 웹 페이지로 리디렉션하고 싶습니다.PHP 폼 - 허니팟 입력 필드가 채워진 경우 - 다른 페이지로 리디렉션

나는 아래 코드를 시도했지만 오류가 발생했습니다. AJAX 요청이 실패했습니다!

그래서 내가 잘못 한 것을 알고 있습니다. 나는 그것이 간단하다고 확신한다.

감사

PHP 코드 :

if(!empty($_POST["e-mail"])) header('Location: blankman.html');exit; 

양식 입력 : 여기

<?php 

if(!empty($_POST["e-mail"])) header('Location: blankman.html');exit; 

// Clean up the input values 
foreach($_POST as $key => $value) { 
    if(ini_get('magic_quotes_gpc')) 
    $_POST[$key] = stripslashes($_POST[$key]); 

    $_POST[$key] = htmlspecialchars(strip_tags($_POST[$key])); 
} 

// Assign the input values to variables for easy reference 
$name = $_POST["name"]; 
$email = $_POST["email"]; 
$message = $_POST["message"]; 


// Test input values for errors 
$errors = array(); 
if(strlen($name) < 2) { 
    if(!$name) { 
    $errors[] = "missing your name"; 
    } else { 
    $errors[] = "your name must be 2 characters"; 
    } 
} 

if(!$email) { 
    $errors[] = "missing your email"; 
} else if(!validEmail($email)) { 
    $errors[] = "you must enter a valid email"; 
} 
if(strlen($message) < 3) { 
    if(!$message) { 
    $errors[] = "missing your message"; 
    } else { 
    $errors[] = "oops! your message is not long enough"; 
    } 
} 

if($errors) { 
    // Output errors and die with a failure message 
    $errortext = ""; 
    foreach($errors as $error) { 
    $errortext .= "<li>".$error."</li>"; 
    } 
$response = array(
    "success" => false, 
    "content" => "<span class='failure'><ul>". $errortext ."</ul></span>" 
); 
die(json_encode($response)); 
} 

// Send the email *********** enter your email address and message info *** 
$to = "[email protected]"; 
$subject = "Website message from: $name"; 
$message = "From:\n$name\n\nEmail:\n$email\n\nMessage:\n$message"; 
$headers = "From: $email"; 

mail($to, $subject, $message, $headers); 

// Die with a success message 
$response = array(
    "success" => true, 
    "content" => "<span class='success'><li>Thank you! Your message has been sent :).</li></span>" 
); 
die(json_encode($response)); 

// A function that checks to see if 
// an email is valid 
function validEmail($email) 
{ 
    $isValid = true; 
    $atIndex = strrpos($email, "@"); 
    if (is_bool($atIndex) && !$atIndex) 
    { 
     $isValid = false; 
    } 
    else 
    { 
     $domain = substr($email, $atIndex+1); 
     $local = substr($email, 0, $atIndex); 
     $localLen = strlen($local); 
     $domainLen = strlen($domain); 
     if ($localLen < 1 || $localLen > 64) 
     { 
     // local part length exceeded 
     $isValid = false; 
     } 
     else if ($domainLen < 1 || $domainLen > 255) 
     { 
     // domain part length exceeded 
     $isValid = false; 
     } 
     else if ($local[0] == '.' || $local[$localLen-1] == '.') 
     { 
     // local part starts or ends with '.' 
     $isValid = false; 
     } 
     else if (preg_match('/\\.\\./', $local)) 
     { 
     // local part has two consecutive dots 
     $isValid = false; 
     } 
     else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)) 
     { 
     // character not valid in domain part 
     $isValid = false; 
     } 
     else if (preg_match('/\\.\\./', $domain)) 
     { 
     // domain part has two consecutive dots 
     $isValid = false; 
     } 
     else if(!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', 
       str_replace("\\\\","",$local))) 
     { 
     // character not valid in local part unless 
     // local part is quoted 
     if (!preg_match('/^"(\\\\"|[^"])+"$/', 
      str_replace("\\\\","",$local))) 
     { 
      $isValid = false; 
     } 
     } 
     if ($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A"))) 
     { 
     // domain not found in DNS 
     $isValid = false; 
     } 
    } 
    return $isValid; 
} 

?> 

는 자바 스크립트입니다 : 여기
<input type="text" name="e-mail" id="e-mail"/> 

전체 PHP 코드입니다 :

<script> 
    $(document).ready(function() { 
     $("#contactform").submit(function (e) { 
      e.preventDefault(); 
      var t = $(this).attr("action"); 
      var n = $(this).serialize(); 
      $.post(t, n, null, "json").done(function (e) { 
       if (e.success) { 
        $("#success").html(e.content); 
        $("#contactform,#error").hide() 
       } else { 
        $("#error").html(e.content) 
       } 
      }).fail(function() { 
       alert("The AJAX request failed!") 
      }) 
     }) 
    }) 
</script> 
+0

당신이 아약스를 통해 양식을 제출? – cmorrissey

+1

아약스 요청은 무엇입니까? 오류 메시지가 나타나면 관련 코드를 제공해야합니다. – JimL

답변

2

는 허니팟가 작성되어있는 경우 다른 어떤 행동하지 쇼를 수행합니다. 이렇게하면 큰 빨간 글씨로 스패머에게 비명을 지르고 있습니다. "허니팟이 있습니다! 해결 방법을 찾아서 작성하십시오!"

항상 정기적 한에 정확히 스팸 요청에 동일한 방식으로 응답 :

if(!empty($_POST["e-mail"])) { 
    $response = array(
     "success" => true, 
     "content" => "<span class='success'><li>Thank you! Your message has been sent :).</li></span>" 
    ); 
    die(json_encode($response)); 
} 
+0

contactme.php 코드는 스팸 봇에 표시되지 않으므로 다른 방식으로 동작하는 것을 볼 수 없습니다. 그것이 리디렉션하기를 원하는 이유이기 때문에 양식을 제출했다고 생각할 수 있습니다. 내가 틀렸어? – mewebs

+0

위치 헤더 **는 ** 다른 동작입니다 –

+0

그래서 무엇을 제안 하시겠습니까? 나는 무엇을 해야할지 알아 내려고 노력하고 있는데 그것이 내가 찾아 낼 수있는 전부입니다. 덕분에 – mewebs

관련 문제