2016-12-22 37 views
1

我有一個表單,我想要添加ReCaptcha,但是,沿線的某個地方某些工作不正常,因爲我的表單仍然會提交是否驗證reCaptcha。表單不檢查reCaptcha

這是形式:

<?php if(isset($_GET[ 'CaptchaPass'])){ ?> 
<div>Thank you! Your Form was Successfully Submitted</div> 
<?php } ?> 
<?php if(isset($_GET[ 'CaptchaFail'])){ ?> 
<div>Captcha Error. Please verify that you are human!</div> 
<?php } ?> 
<form action="http://vmobileautoglass.com/php/func_contact.php"> 
    <label>Name</label> <span class="color-red">*</span> 
    <div class="row margin-bottom-20"> 
     <div class="col-md-6 col-md-offset-0"> 
      <input class="form-control" type="text" name="name"> 
     </div> 
    </div> 
    <label>Email 
     <span class="color-red">*</span> 
    </label> 
    <div class="row margin-bottom-20"> 
     <div class="col-md-6 col-md-offset-0"> 
      <input class="form-control" type="text" name="email"> 
     </div> 
    </div> 
    <label>Phone 

    </label> 
    <div class="row margin-bottom-20"> 
     <div class="col-md-6 col-md-offset-0"> 
      <input class="form-control" type="text" name="phone"> 
     </div> 
    </div> 
    <label>Message</label> <span class="color-red">*</span> 
    <div class="row margin-bottom-20"> 
     <div class="col-md-8 col-md-offset-0"> 
      <textarea rows="8" class="form-control" name="message"></textarea> 
     </div> 
    </div> 
    <div class="g-recaptcha" data-sitekey="MYSITEKEYFROMGOOGLE"></div> 
    <p> 
     <button type="submit" class="btn btn-primary" name="ContactButton">Send Message</button> 
    </p> 
</form> 

這又在頁面的最頂端,其中窗體位於:

<?php 

if (isset($_POST['ContactButoon'])) { 

    $url = 'https://google.com/recaptcha/api/siteverify'; 
    $privatekey = "MYPRIVATEKEYFROMGOOGLE"; 

    $response = file_get_contents($url . "?secret=" . $privatekey . "&response=" . $_POST['g-recaptcha-response'] . "&remoteip=" . $_SERVER['REMOTE_ADDR']); 
    $date = json_decode($response); 

    if (isset($data->success) AND $data->success == true) { 
     header('Location: contact.php?CaptchaPasss=True'); 
    } else { 
     header('Location: contact.php?CaptchaFail=True'); 
    } 
} 
?> 

這是表單功能:

// Receiving variables 
@$pfw_ip = $_SERVER['REMOTE_ADDR']; 
@$name = addslashes($_GET['name']); 
@$email = addslashes($_GET['email']); 
@$phone = addslashes($_GET['phone']); 
@$message = addslashes($_GET['message']); 

// Validation 
if (strlen($name) == 0) { 
    header("Location: http://vmobileautoglass.com/php/err_name.php"); 
    exit; 
} 

if (strlen($email) == 0) { 
    header("Location: http://vmobileautoglass.com/php/err_email.php"); 
    exit; 
} 

if (strlen($message) == 0) { 
    header("Location: http://vmobileautoglass.com/php/err_message.php"); 
    exit; 
} 

//Sending Email to form owner 
$pfw_header = "From: $email\n" 
     . "Reply-To: $email\n"; 
$pfw_subject = "vMobile Contact Form"; 
$pfw_email_to = "[email protected]"; 
$pfw_message = "Visitor's IP: $pfw_ip\n" 
     . "name: $name\n" 
     . "email: $email\n" 
     . "phone: $phone\n" 
     . "message: $message\n"; 
@mail($pfw_email_to, $pfw_subject, $pfw_message, $pfw_header); 

header("Location: http://vmobileautoglass.com/php/successform.php"); 

回答

1

你有一個錯字:

$date = json_decode($response); 

    if(isset($data->success) AND $data->success==true){ 

$日期應該是$數據。

+0

謝謝。固定的,但問題仍然存在。 –

+0

請提供更多的信息,是$響應變量數組? – Illuminati