错误卷曲功能
问题描述:
嘿,我试图卷曲“https://www.libertyreserve.com/captcha.jpg”
所以我试图卷曲它,但结果却是“1×1”的Gif产品图
然后我reialized,该网站希望从登录一个cookie页面显示有效的验证码 我使用的功能错误卷曲功能
$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, like 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;
}
然后我卷曲登录页面
$LoginPage = cURL_Page("https://www.libertyreserve.com/en/login");
然后卷曲在PIC,并把报头和打印
$ImageCode = cURL_Page("https://www.libertyreserve.com/captcha.jpg");
header("Content-Type: image/gif");
echo $ImageCode;
,但结果仍然是“1×1” BCZ卷曲功能不;吨保存的cookies
PS:网站的响应与“内容类型:image/GIF”为我把它放在头
答
很少观察
- 你是不是正确共享
cookie
是因为你不需要CURLOPT_COOKIE
- 即使SSL验证是假的..你需要添加认证信息,请参阅Code does not work without disabling SSL如何可以做
这里是工作的代码:
$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();
}
输出
类用于
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);
}
}