duanli8577
2015-06-24 10:43
浏览 82
已采纳

php curl不会写cookie文件

I know there are loads of question like this, but could anyone help me narrow down what the issue is?

This is my code:

ini_set("display_errors", 1);
error_reporting(E_ALL);
$cookies = 'cookies.txt';
$postdatal = array(
    '__VIEWSTATE' => '', // need a __VIEWSTATE, even if it's empty
    'username' => 'username',
    'password' => 'password',
    'button1' => 'Sign+in', // need button1
    '__VIEWSTATEGENERATOR' => '' // same reason as __VIEWSTATE
);

$ch = curl_init();

curl_setopt_array( 
$ch, array(
    CURLOPT_URL => 'url',
    CURLOPT_RETURNTRANSFER => true, // return the results
    CURLOPT_POST => true, 
    CURLOPT_POSTFIELDS => $postdatal, // send the data
    CURLOPT_HEADER => true,
    CURLOPT_COOKIEJAR => $cookies, // set the cookies
    CURLOPT_COOKIEFILE => $cookies 
));

$output = curl_exec($ch);

echo $output;

The headers returned have three Set-Cookie headers. Is there any way I could debug this? I don't seem to get any errors, even if I choose an invalid file name (cookies.txt is a chmod 777 empty text file).

图片转代码服务由CSDN问答提供 功能建议

我知道有很多这样的问题,但任何人都可以帮我缩小问题范围吗?

这是我的代码:

  ini_set(“display_errors”,1); 
error_reporting(E_ALL); 
 $ cookies ='cookies  .txt'; 
 $ postdatal = array(
'__VIEWSTATE'=>'',//需要__VIEWSTATE,即使它是空的
'用户名'=>'用户名',
'密码'=  >'password',
'button1'=>'Sign + in',//需要button1 
'__VIEWSTATEGENERATOR'=>''//与__VIEWSTATE相同的原因
); 
 
 $ ch  = curl_init(); 
 
curl_setopt_array(
 $ ch,array(
 CURLOPT_URL =>'url',
 CURLOPT_RETURNTRANSFER => true,//返回结果
 CURLOPT_POST => true,
  CURLOPT_POSTFIELDS => $ postdatal,//发送数据
 CURLOPT_HEADER => true,
 CURLOPT_COOKIEJAR => $ cookies,//设置cookies 
 CURLOPT_COOKIEFILE => $ cookies 
)); 
 \  n $ output = curl_exec($ ch); 
 
echo $ output; 
   
 
 

返回的标头有三个Set-Cookie标头。 有什么办法可以调试吗? 我似乎没有得到任何错误,即使我选择了无效的文件名(cookies.txt是chmod 777空文本文件)。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题