2014-10-15 1 views
0

이 양식에 보안 문자를 추가하려고합니다. 원하는 경우 링크를 확인하십시오.양식에 보안 문자 추가가 올바르지 않습니다.

This is the link from Stackoverflow

하지만 난 내가 보안 문자 아무 문제가 발생하지 입력 할 때 제대로 작동 할 수 없습니다, 그리고 난 여전히 메일을받을 수 있습니다.

<?php 
session_start(); 
$cap = 'notEq'; 
if ($_SERVER['REQUEST_METHOD'] == 'POST') { 
    if ($_POST['captcha'] == $_SESSION['cap_code']) { 
     // Captcha verification is Correct. Do something here! 
     $cap = 'Eq'; 
    } else { 
     // Captcha verification is wrong. Take other action 
     $cap = ''; 
    } 



    $to = "[email protected]"; // this is your Email address 
    $from = $_POST['email']; // this is the sender's Email address 
    $first_name = $_POST['first_name']; 
    $last_name = $_POST['last_name']; 
    $ip = $_POST['ip']; 
    $subject = "Form submission"; 
    $subject2 = "Copy of your form submission"; 
    $message = $first_name . " " . $last_name . " wrote the following:" . " " . $_POST['message']; 
    $message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message']; 

    $headers = "From:" . $from; 
    $headers2 = "From:" . $to; 
    mail($to,$subject,$message,$headers); 
    mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender 
    echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly."; 
    // You can also use header('Location: thank_you.php'); to redirect to another page. 

} 

?> 

다음은 captcha 및 제출 버튼입니다.

<!-- Captcha --> 
<input type="text" name="captcha" id="captcha" maxlength="6" size="6"/> 


    <!-- Submit Button --> 
<input type="submit" id="captcha" name="captcha" value="Submit"> 

그래서 내가 뭘 잘못하고 있니?

도움 주셔서 감사합니다.

+0

어디, – RiggsFolly

+0

가 @RiggsFolly 스크립트가 작동 $ _SESSION [ 'cap_code']의 보안 문자 값 저장을 설정하는 코드를 실행하는 .com ")까지 (끝 PHP 태그?>) – Tasos

+0

당신은 자신의 것을 만들려고 시도하는 대신에 google recaptcha를 사용할 수 있습니까? 많은 캡쳐 이미지가 개인적으로 만드는 것보다 훨씬 더 간단해질 것입니다. http://www.google.com/recaptcha/intro/ – Parody

답변

0

두 입력 필드의 이름이 같으므로 텍스트 필드의 내용이 제출 버튼의 값으로 대체됩니다.

제출 단추 이름을 변경하십시오. 내가 ($로 = "예를 들어 @ 메일에서이 부분을 추가 할 때까지

<input type="text" name="captcha" id="captcha" maxlength="6" size="6"/> 

<!-- Submit Button --> 
<input type="submit" id="captchaBut" name="captchaBut" value="Submit"> 
관련 문제