How can I make cURL set a cookie relative to the script?

孤者浪人 提交于 2019-12-11 13:32:02

问题


EDIT: How can I change the relative path to 'relative-to-this-file' mode? Like on my host...


I've got a cURL PHP script which works. It gets my schedule from my school site. Though there is one strange thing: On my webhost it creates the cookie.txt and on my localhost it doesn't.

  • Why doesn't cURL create a cookie on my localhost? Something with relative paths and wampserver? Maybe some settings on wamp?

I am using:

  • WampServer
  • Windows 7

cURL does create a cookie if I use: '/cookie.txt' but ofcourse it creates it in my c:/. And that is obviously not where I want it to be. Also I want to prevent using full paths.


回答1:


be sure you have these two options in the curl setup phase

$cookiefile = dirname(__FILE__)."/cookie.txt" ; 
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookiefile);
curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookiefile);

they will create a cookie in the folder your script resides in

EDIT : added option to set the cookie in the same dir as the script is running in



来源:https://stackoverflow.com/questions/9018155/how-can-i-make-curl-set-a-cookie-relative-to-the-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!