如何使cURL相对于脚本设置一个cookie? [英] How can I make cURL set a cookie relative to the script?
问题描述
EDIT :如何将相对路径更改为相对于此文件模式?像我的主机...
EDIT: How can I change the relative path to 'relative-to-this-file' mode? Like on my host...
我有一个 cURL PHP
script。它从我的学校网站得到我的时间表。虽然有一个奇怪的事情:在我的 webhost 它创建cookie.txt和在我的 localhost 它不。
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.
- 为什么cURL在我的本地主机上创建一个cookie?有相对路径和wampserver的东西?也许在wamp上有一些设置?
我使用的是:
- WampServer
- Windows 7
cURL :'/cookie.txt'但是它创建它在我的c:/。这显然不是我想要的地方。
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.
推荐答案
请确保curl设置阶段有这两个选项
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);
他们将在您脚本所在的文件夹中创建一个cookie
they will create a cookie in the folder your script resides in
EDIT:添加选项以将脚本设置为与脚本运行时相同的目录
EDIT : added option to set the cookie in the same dir as the script is running in
这篇关于如何使cURL相对于脚本设置一个cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!