appleboy / CodeIgniter-reCAPTCHA

reCAPTCHA library for CodeIgniter
https://www.google.com/recaptcha/intro/index.html
BSD 3-Clause "New" or "Revised" License
106 stars 82 forks source link

Unable to run file_get_contents due to shared hosting restrictions #3

Closed mgilberties closed 5 years ago

mgilberties commented 8 years ago

Due to my restrictions on a shared server, I am unable to run file_get_contents or even set

allow_url_fopen = on

Therefore I had to edit the library file: CodeIgniter-reCAPTCHA/libraries/Recaptcha.php

My changes aren't very clean, but could the concept be used to detect lack of support and use CURL instead?

/**
* 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')) {
        $ch = curl_init();
        $options = array(CURLOPT_URL => $url,
                                   CURLOPT_CONNECTTIMEOUT => 5,
                                   CURLOPT_RETURNTRANSFER => true
        );
        curl_setopt_array($ch, $options);

        $response = curl_exec($ch);
        if (curl_errno($ch)) { 
            $response = '';
        } else {
            curl_close($ch);
        }

        if (!is_string($response) || !strlen($response)) {
            $response = 'Failed to get contents';
       }
   } else {
       $response = file_get_contents($url);
   }

    return $response;
}

Feedback much appreciated.

pioneersingh321 commented 6 years ago

this is easy way without changing many thing

private function _submitHTTPGet($data) { $arrContextOptions=array( "ssl"=>array( "verify_peer"=>false, "verify_peer_name"=>false, ), );

    $url = self::site_verify_url.'?'.http_build_query($data);
    $response = file_get_contents($url, false, stream_context_create($arrContextOptions));
    return $response;
}
appleboy commented 5 years ago

9 merged, so closed this issue.