如何使Google Recaptcha在UC浏览器中工作?

时间:2019-01-05 06:23:35

标签: php html web recaptcha uc-browser

对于一个项目,我实现了Google Recaptcha V2(带有图片选择)。我可以在其他所有浏览器中使用Google Recaptcha,但在UC浏览器移动版中除外。

示例代码(html):

    <head>
       <script src='https://www.google.com/recaptcha/api.js'></script>
         <style>.g-recaptcha {transform:scale(0.77);-webkit-transform:scale(0.77);transform-origin:0 0;-webkit-transform-origin:0 0;}</style>
</script>
<head>
    <form action="contact-email.php" method="post">
                                       <div class="row">
                                          <div class="form-group col-lg-6 col-md-6 col-sm-6 padysclass">
                                             <label>First Name*</label>
                                             <input type="text" class="form-control" id="fname" name="fname"
                                             data-validation="required" required="">
                                          </div>
                                          <div class="form-group col-lg-6 col-md-6 col-sm-6 padnoclass" style="">
                                             <label>Last Name*</label>
                                             <input type="text" class="form-control" id="lname" name="lname"
                                             data-validation="required" required="">
                                          </div>
                                       </div>
                                       <div class="row">
                                          <div class="form-group  col-lg-6 col-md-6 col-sm-6 padysclass">
                                             <label>Phone*</label>
                                             <input type="text" class="form-control" id="connumber" name="connumber"
                                             data-validation="length" data-validation-length="6-15" required=""
                                             data-validation-error-msg="Please provide a valid number">
                                          </div>
                                          <div class="form-group  col-lg-6 col-md-6 col-sm-6 padnoclass">
                                             <label>Email*</label>
                                             <input type="email" class="form-control" id="email" name="email"
                                             data-validation="email" required=""
                                             data-validation-error-msg="You have not given valid email-id">
                                          </div>
                                       </div>
                                       <div class="row">
                                          <div class="form-group">
                                             <label>Subject :</label>
                                             <input type="text" class="form-control" id="subject" name="subject">
                                          </div>
                                          <div class="form-group">
                                             <label>Message :</label>
                                             <textarea class="form-control" id="comment" name="comment"></textarea>
                                          </div>
                                          <div class="g-recaptcha"
                                          data-sitekey="SITEKEY"></div>
                                          <div class="form-group">
                                             <button type="submit" class="btn active btn-sm subbutn">Submit</button>
                                             <button type="reset" class="btn btn-sm subbutn">Reset</button>
                                          </div>
                                       </div>
                                    </form>

contact-email.php()

    <?php
$fname = $_POST["fname"];
$lname = $_POST["lname"];
$connumber = $_POST["connumber"];
$email = $_POST["email"];
$form_subject = $_POST["subject"];
$comment = $_POST["comment"];

if(isset($_SERVER['HTTP_REFERER'])) {
    $current_url=$_SERVER['HTTP_REFERER'];
}
if(isset($_SERVER['REMOTE_ADDR'])) {
    $ip = $_SERVER['REMOTE_ADDR'];
}

$captcha = "";
$captcha=$_POST["g-recaptcha-response"];


if ($captcha == "") {
    $current_url_data=$current_url.'?r';
    header('Location:'.$current_url_data);
    exit();
}

$secretKey = "SECRET_KEY";
$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
$responseKeys = json_decode($response,true);
if(intval($responseKeys["success"]) !== 1) {
    $current_url_data=$current_url.'?r';
    header('Location:'.$current_url_data);
    exit();
}

$msg = "First Name : " . $fname . "<br>Last Name : " . $lname . "<br>Phone : " . $connumber . "<br>Email : " . $email ."<br>Form Subject : " . $form_subject . "<br>Message : " . $comment;
$to = "sampleemail1@email.com";

$subject = "Contact Enquiry From ATEES.SG";

$headers = "From: " . $email . "\r\n";
$headers .= "Reply-To: " . $email . "\r\n";
$headers .= "Return-Path: " . $email . "\r\n";
$headers .= "CC: sampleemail2@email.com\r\n";
$headers .= "CC: sampleemail3@email.com \r\n";

$headers .= "Content-type: text/html\r\n";

$email_val = mail("$to", "$subject", "$msg", "$headers");
if ($email_val)
    {   $current_url_data=$current_url.'?s';
        header('Location:'.$current_url_data);
    }
else
    {
        $current_url_data=$current_url.'?f';
        header('Location:'.$current_url_data);
    }
?>

HTML代码用于包含Recaptcha的表单。 PHP代码用于处理表单数据和发送电子邮件。

我可以在UC浏览器中运行它吗? 我该怎么解决?

谢谢。

0 个答案:

没有答案