hCaptcha
This commit is contained in:
@@ -18,7 +18,28 @@ class Contact extends CI_Controller {
|
||||
extract($_POST);
|
||||
|
||||
if ($_POST) {
|
||||
|
||||
$resp = $this->input->post('h-captcha-response');
|
||||
$secret = "0x608809f0227f7FA577E069524805cC25f5E732C0";
|
||||
$url = "https://hcaptcha.com/siteverify";
|
||||
$data = array(
|
||||
"secret" => $secret,
|
||||
"response" => $resp
|
||||
);
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch,CURLOPT_URL, $url);
|
||||
curl_setopt($ch,CURLOPT_POST, count($data));
|
||||
curl_setopt($ch,CURLOPT_POSTFIELDS, http_build_query($data));
|
||||
curl_setopt($ch,CURLOPT_RETURNTRANSFER, TRUE);
|
||||
$result = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
$captcha = json_decode($result,true);
|
||||
if (is_array($captcha) && array_key_exists("success",$captcha) && $captcha["success"]) {
|
||||
// Ok
|
||||
$message = '';
|
||||
} else {
|
||||
$message = 'Please verify that you are human';
|
||||
}
|
||||
|
||||
$email = $this->input->post('email');
|
||||
$firstname = $this->input->post('firstname');
|
||||
$lastname = $this->input->post('lastname');
|
||||
|
||||
@@ -91,6 +91,36 @@
|
||||
<textarea rows="5" cols="5" class="form-control" name="msg" placeholder="Enter your message here" onkeydown="textCounter(this.form.msg, this.form.remLen, 500);" onkeyup="textCounter(this.form.msg, this.form.remLen, 500);"><?= $msg ?></textarea>
|
||||
<input type="text" class="form-control" name="remLen" value="<?= (500 - strlen($msg)) ?>" placeholder="0" style='width: 50px;' readonly>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-lg-3 control-label">Verify:</label>
|
||||
<div class="col-lg-9">
|
||||
<div id="hcaptcha-demo" class="h-captcha" data-sitekey="8f17e5c1-1a95-4788-a58c-b406c70923f7" data-callback="onSuccess" data-expired-callback="onExpire"></div>
|
||||
<script>
|
||||
// success callback
|
||||
var onSuccess = function(response) {
|
||||
var errorDivs = document.getElementsByClassName("hcaptcha-error");
|
||||
if (errorDivs.length) {
|
||||
errorDivs[0].className = "";
|
||||
}
|
||||
var errorMsgs = document.getElementsByClassName("hcaptcha-error-message");
|
||||
if (errorMsgs.length) {
|
||||
errorMsgs[0].parentNode.removeChild(errorMsgs[0]);
|
||||
}
|
||||
|
||||
var logEl = document.querySelector(".hcaptcha-success");
|
||||
logEl.innerHTML = "Challenge Success!"
|
||||
};
|
||||
|
||||
var onExpire = function(response) {
|
||||
var logEl = document.querySelector(".hcaptcha-success");
|
||||
logEl.innerHTML = "Token expired."
|
||||
};
|
||||
</script>
|
||||
<div class="hcaptcha-success smsg" aria-live="polite"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="text-right">
|
||||
@@ -116,3 +146,5 @@
|
||||
|
||||
</div>
|
||||
<!-- /page container -->
|
||||
<script src="https://hcaptcha.com/1/api.js?reportapi=https%3A%2F%2Faccounts.hcaptcha.com" type="text/javascript" async defer></script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user