|
Server : Apache/2.4.18 (Ubuntu) System : Linux canvaswebdesign 3.13.0-71-generic #114-Ubuntu SMP Tue Dec 1 02:34:22 UTC 2015 x86_64 User : oppastar ( 1041) PHP Version : 7.0.33-0ubuntu0.16.04.15 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, Directory : /var/www/kamariallee.com/public_html/application/libraries/ |
Upload File : |
<?php (! defined('BASEPATH')) and exit('No direct script access allowed');
/**
* CodeIgniter Recaptcha library
*
* @package CodeIgniter
* @author Bo-Yi Wu <appleboy.tw@gmail.com>
* @link https://github.com/appleboy/CodeIgniter-reCAPTCHA
*/
class Recaptcha
{
private $_siteKey;
private $_secretKey;
private $_language;
/**
* ci instance object
*
*/
private $_ci;
/**
* reCAPTCHA site up, verify and api url.
*
*/
const sign_up_url = 'https://www.google.com/recaptcha/admin';
const site_verify_url = 'https://www.google.com/recaptcha/api/siteverify';
const api_url = 'https://www.google.com/recaptcha/api.js';
/**
* constructor
*
* @param string $config
*/
public function __construct()
{
$this->_ci = & get_instance();
$this->_ci->load->config('recaptcha');
// $this->_siteKey = $this->_ci->config->item('recaptcha_site_key');
// $this->_secretKey = $this->_ci->config->item('recaptcha_secret_key');
// $this->_language = $this->_ci->config->item('recaptcha_lang');
$this->_siteKey = '6LcHMucqAAAAAFkS1ayBuCCjskW1El8w7PLhIbBV';
$this->_secretKey = '6LcHMucqAAAAAMNyPCH5dt2S8ScW1eDZwymbFHd0';
$this->_language = 'en';
if (empty($this->_siteKey) or empty($this->_secretKey)) {
die("To use reCAPTCHA you must get an API key from <a href='"
.self::sign_up_url."'>".self::sign_up_url."</a>");
}
}
/**
* Submits an HTTP GET to a reCAPTCHA server.
*
* @param array $data array of parameters to be sent.
*
* @return array response
*/
private function _submitHTTPGet($data)
{
$url = self::site_verify_url.'?'.http_build_query($data);
if( ini_get('allow_url_fopen') ) {
$response = file_get_contents($url);
} else {
$ch = curl_init();
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$response = curl_exec($ch);
curl_close($ch);
}
return $response;
}
/**
* Calls the reCAPTCHA siteverify API to verify whether the user passes
* CAPTCHA test.
*
* @param string $response response string from recaptcha verification.
* @param string $remoteIp IP address of end user.
*
* @return ReCaptchaResponse
*/
public function verifyResponse($response, $remoteIp = null)
{
$remoteIp = (!empty($remoteIp)) ? $remoteIp : $this->_ci->input->ip_address();
// Discard empty solution submissions
if (empty($response)) {
return array(
'success' => false,
'error-codes' => 'missing-input',
);
}
$getResponse = $this->_submitHttpGet(
array(
'secret' => $this->_secretKey,
'remoteip' => $remoteIp,
'response' => $response,
)
);
// get reCAPTCHA server response
$responses = json_decode($getResponse, true);
if (isset($responses['success']) and $responses['success'] == true) {
$status = true;
} else {
$status = false;
$error = (isset($responses['error-codes'])) ? $responses['error-codes']
: 'invalid-input-response';
}
return array(
'success' => $status,
'error-codes' => (isset($error)) ? $error : null,
);
}
/**
* Render Script Tag
*
* onload: Optional.
* render: [explicit|onload] Optional.
* hl: Optional.
* see: https://developers.google.com/recaptcha/docs/display
*
* @param array parameters.
*
* @return scripts
*/
public function getScriptTag(array $parameters = array())
{
$default = array(
'render' => 'onload',
'hl' => $this->_language,
);
$result = array_merge($default, $parameters);
$scripts = sprintf('<script type="text/javascript" src="%s?%s" async defer></script>',
self::api_url, http_build_query($result));
return $scripts;
}
/**
* render the reCAPTCHA widget
*
* data-theme: dark|light
* data-type: audio|image
*
* @param array parameters.
*
* @return scripts
*/
public function getWidget(array $parameters = array())
{
$default = array(
'data-sitekey' => $this->_siteKey,
'data-theme' => 'light',
'data-type' => 'image',
'data-size' => 'normal',
);
$result = array_merge($default, $parameters);
$html = '';
foreach ($result as $key => $value) {
$html .= sprintf('%s="%s" ', $key, $value);
}
return '<div class="g-recaptcha" '.$html.'></div>';
}
}