php curl curloptcookiesession,curlopt_cookie问题

我使用curlopt_cookie 发现前一个COOKIE会覆盖后一个COOKIE。。而且写法上也出现了问题,打印的结果不是想要的,不正确的

$PostData = array( 'zipCode' => '12345', 'langId' => '-1', 'storeId' => '10001', 'URL' => '/Brother-TN-580-Toner-Cartridge-High-Yield/product_612784', 'errorUrl' => 'zipcode' );$ua = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)'; $url = 'http://www.staples.com/Brother-TN-580-Toner-Cartridge-High-Yield/product_612784';$host = $_SERVER['DOCUMENT_ROOT'];if ( $curl = curl_init() ){ curl_setopt($curl, CURLOPT_URL, 'http://www.chenzhi.com/2.php'); curl_setopt($curl, CURLOPT_COOKIE, 'CoreID6=30201255514912193294815;Path=/;Domain=www.chenzhi.com;expires=Mon, 13-Oct-24 13:08:16 GMT'); curl_setopt($curl, CURLOPT_COOKIE, 'TestSess3=x;Path=/;Domain=www.chenzhi.com;expires=End Of Session'); curl_setopt($curl, CURLOPT_COOKIE, '90028341_login=1255528626018461671490028341;Path=/;Domain=www.chenzhi.com;expires=End Of Session'); curl_setopt($curl, CURLOPT_COOKIE, '90028341_reset=1255528626;Path=/;Domain=www.chenzhi.com;expires=End Of Session'); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, false); curl_exec($curl); curl_close($curl);} else { die('1 fails:' . curl_error($curl));}unset($curl);

打印的结果

Array( [90028341_reset] => 1255528626 [Path] => / [Domain] => www.chenzhi.com [expires] => End Of Session)

而正常的setcookie显示的结果确是

';print_r($_COOKIE);echo '';

Array( [TestCookie1] => 1 [TestCookie2] => 2 [TestCookie3] => 3 [TestCookie4] => 4)

请问大神们如何把多个COOKIE的值用CURLOPT_COOKIE写出来??求解

回复讨论(解决方案)

多个 COOKIE 变量用分号分开即可

一般网站不大可能始终都是静态的 cookie,一般应用 CURLOPT_COOKIEJAR 动态获取到文件,并用 CURLOPT_COOKIEFILE 发送

多个 COOKIE 变量用分号分开即可

一般网站不大可能始终都是静态的 cookie,一般应用 CURLOPT_COOKIEJAR 动态获取到文件,并用 CURLOPT_COOKIEFILE 发送

我前面写的就是用分号隔开的curl_setopt($curl, CURLOPT_COOKIE, 'CoreID6=30201255514912193294815;Path=/;Domain=www.chenzhi.com;expires=Mon, 13-Oct-24 13:08:16 GMT'); curl_setopt($curl, CURLOPT_COOKIE, 'TestSess3=x;Path=/;Domain=www.chenzhi.com;expires=End Of Session'); curl_setopt($curl, CURLOPT_COOKIE, '90028341_login=1255528626018461671490028341;Path=/;Domain=www.chenzhi.com;expires=End Of Session'); curl_setopt($curl, CURLOPT_COOKIE, '90028341_reset=1255528626;Path=/;Domain=www.chenzhi.com;expires=End Of Session');照这么说只用写一个就好了,用;隔开,那path ,domain,expires这些怎么写进去

还有版主能详细说下CURLOPT_COOKIEJAR CURLOPT_COOKIEFILE 的用法么,动态获取不是很懂,给点资料看看也行

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值