Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/254.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 同一会话中的多个cURL操作_Php_Curl - Fatal编程技术网

Php 同一会话中的多个cURL操作

Php 同一会话中的多个cURL操作,php,curl,Php,Curl,首先,我知道curl_multi_init,但据我所知,它并不完全满足我的需要 我在登录后下载文件,所以 a) 需要登录吗 b) 下载图片 这是我目前拥有的 $login_url = 'https://us.test.com/Member/Login'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$login_url); curl_setopt($ch, CURLOPT_POSTFIELDS, 'login='.$this->user

首先,我知道curl_multi_init,但据我所知,它并不完全满足我的需要

我在登录后下载文件,所以

a) 需要登录吗 b) 下载图片

这是我目前拥有的

$login_url = 'https://us.test.com/Member/Login';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$login_url);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'login='.$this->username.'&password='.$this->userpass.'&signin=1&login_referer=none&remember_me=1');
curl_setopt($ch, CURLOPT_FAILONERROR,1);  
curl_setopt($ch, CURLOPT_COOKIEFILE, $_SERVER['DOCUMENT_ROOT'].'/test/cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, $_SERVER['DOCUMENT_ROOT'].'/test/cookie.txt');  
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST, true);   
curl_exec($ch);

//Grab and Write the image
$image = file_get_contents($image_url); 
$f = fopen($_SERVER['DOCUMENT_ROOT'].'/test/uploads/'.$id.'.jpg', 'w');
fwrite($f, $image);
fclose($f);  


curl_close($ch);

非常感谢您的帮助。

我想出来了,只是在cURL中添加了会话ID。但是一个快速而肮脏的方法是

$download_str='wget-O'$保存$身份证。jpg--cookies=off--header“Cookie:PHPSESSID=”.$session_id.”$图片地址


shell_exec($download_str)

您可以通过curl获得auth cookie,但是您不能使用它们下载图像。您是否尝试过使用cookie文件从登录名通过curl下载它?