0

对于一个项目,我实现了 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>

联系电子邮件.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 浏览器中运行它吗?我该如何解决这个问题?

谢谢。

4

0 回答 0