Error in cURL Function Error in cURL Function curl curl

Error in cURL Function


Few Observation

  • You are not properly sharing the cookie be cause you don't need CURLOPT_COOKIE
  • Even if SSL verification is false .. you need to add certification information see Code does not work without disabling SSL on how that can be done

Here is a working code:

$ch = new SharedCurl(__DIR__ . "\libertyreserve.crt");try {    $ch->get('https://www.libertyreserve.com/en/login');    $image = $ch->get('https://www.libertyreserve.com/captcha.jpg');    header("Content-Type: image/gif");    echo $image;} catch (Exception $e) {    print $e->getMessage();}

Output

enter image description here

Class Used

class SharedCurl {    private $ch;    private $info;    function __construct($cert) {        $this->cookie = tempnam("/tmp", "CURLCOOKIE");        $this->cert = $cert;        if (! is_file($this->cert)) {            throw new Exception("Can't find Certificate");        }    }    function get($url) {        $this->ch = curl_init($url);        $this->shared();        $responce = curl_exec($this->ch);        $this->info = curl_getinfo($this->ch);        if (curl_errno($this->ch)) {            throw new Exception(curl_error($this->ch));        }        curl_close($this->ch);        return $responce;    }    function shared() {        curl_setopt($this->ch, CURLOPT_CONNECTTIMEOUT, 20);        curl_setopt($this->ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31');        curl_setopt($this->ch, CURLOPT_REFERER, "http://www.libertyreserve.com/en/login");        curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true);        curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);        curl_setopt($this->ch, CURLOPT_COOKIEJAR, $this->cookie);        curl_setopt($this->ch, CURLOPT_COOKIEFILE, $this->cookie);        curl_setopt($this->ch, CURLOPT_CAINFO, $this->cert);        curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, 0);        curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, 0);    }}

Certificate File Used