我的 cURL 脚本在我的localhost 上不再 不再起作用(所以请记住它之前确实起作用)(所以它确实在我的外部主机上起作用,因此:它可能是服务器设置):
这个脚本之前在我的本地主机上运行良好(它仍然在我的主机上运行)。没有改变。
- 也许我已经在我的本地主机上运行了这个脚本 3000 多次这一事实对了解这一点很有用。
- 我在 Windows 7 上运行,使用 WampServer 设置主机。
- 我可能更改了设置,这会影响 cookie 的写入。但是哪个呢?
真正的问题:cURL 没有设置 cookie!应该打开哪些 apache 模块来写入 cookie(在 .txt 文件中)?我正在运行 wampserver。
请注意我已经在使用:
curl_setopt($curlTable, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($curlTable, CURLOPT_COOKIEFILE, 'cookie.txt');
那个 php.ini 是:
extension=php_curl.dll is uncommented
- 附带问题:curl_close 是否取消设置 cookie?如果未设置 cookiejar 选项?
- 主要问题:为什么 curl 没有像它应该做的那样写一个 cookie(而是在我的外部主机上写,而不是在我的本地主机上写。
其他信息:
phpinfo()
curl
cURL support enabled
cURL Information 7.21.7
Age 3
Features
AsynchDNS Yes
Debug No
GSS-Negotiate Yes
IDN No
IPv6 Yes
Largefile Yes
NTLM Yes
SPNEGO No
SSL Yes
SSPI Yes
krb4 No
libz Yes
CharConv No
Protocols dict, file, ftp, ftps, gopher,
http, https, imap, imaps, ldap, pop3,
pop3s, rtsp, scp, sftp, smtp, smtps, telnet, tftp
Host i386-pc-win32
SSL Version OpenSSL/0.9.8r
ZLib Version 1.2.5
libSSH Version libssh2/1.2.7
当前使用:
preg_match('/name="csrf" value="(.*?)"/', $getTokenCurlData, $token);
$postFields = array(
'user' => $userNum,
'paswoord' => $userPass,
'login' => 'loginform',
'csrf' => $token[1]);
// 'user='.$userNum.'&paswoord='.$userPass.'&login=loginform&csrf='.$token[1]
$postData = http_build_query($postFields);
$curlTable = curl_init();
curl_setopt($curlTable, CURLOPT_URL, 'link');
curl_setopt($curlTable, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($curlTable, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt($curlTable, CURLOPT_ENCODING, 'gzip');
curl_setopt($curlTable, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curlTable, CURLOPT_POST, true);
$tableData = curl_exec($curlTable);
if (!$tableData) echo 'post problem?'.$tableData;
if ($tableData == false)
{
echo 'Curl error: ' . curl_error($curlTable);
}
curl_close($curlTable);
// Here I further process my data.
最佳答案
虽然这个问题有点过时了,但我今天遇到了同样的问题,并没有用这里的任何建议解决它。未保存 cookie 的原因仅仅是缺少调用
curl_close()
如果在 curl 请求之后没有调用 curl_close,cookie 不会被保存。
我花了大约一个小时才知道....也许可以节省您的时间:-)
关于php - cURL 不再设置 cookie,但为什么呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8960977/