php - Error in cURL Function -
hey i'm trying curl "https://www.libertyreserve.com/captcha.jpg"
tried curl result "1x1" gif pic
reialized site want cookie login page show valid captcha used function
$file['cookie'] = "cookie.txt"; function curl_page($url='',$var=''){ global $file; $curl = curl_init(); curl_setopt($curl, curlopt_url, $url); curl_setopt($curl, curlopt_connecttimeout,20); curl_setopt($curl, curlopt_useragent, 'mozilla/5.0 (windows nt 6.2; wow64) applewebkit/537.31 (khtml, gecko) chrome/26.0.1410.64 safari/537.31'); curl_setopt($curl, curlopt_referer, "http://www.libertyreserve.com/en/login"); curl_setopt($curl, curlopt_followlocation, true); if($var) { curl_setopt($curl, curlopt_post, 1); curl_setopt($curl, curlopt_postfields, $var); } curl_setopt($curl, curlopt_cookie,$file['cookie']); curl_setopt($curl, curlopt_cookiefile,$file['cookie']); curl_setopt($curl, curlopt_cookiejar,$file['cookie']); curl_setopt($curl, curlopt_ssl_verifyhost, 3); curl_setopt($curl, curlopt_header, 0); curl_setopt($curl, curlopt_returntransfer, true); curl_setopt($curl, curlopt_ssl_verifypeer, false); $result = curl_exec($curl); curl_close($curl); return $result; }
then curl login page
$loginpage = curl_page("https://www.libertyreserve.com/en/login");
then curl pic , put header , print
$imagecode = curl_page("https://www.libertyreserve.com/captcha.jpg"); header("content-type: image/gif"); echo $imagecode;
but result still "1x1" bcz curl function don;t save cookies
p.s : site response "content-type: image/gif" put in header
few observation
- you not sharing
cookie
cause don't needcurlopt_cookie
- even if ssl verification false .. need add certification information see code not work without disabling ssl on how can done
here 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
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, 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); } }
Comments
Post a Comment