【发布时间】:2012-01-25 18:12:26
【问题描述】:
我有一个有效的cURL PHP 脚本。它从我的学校网站获取我的日程安排。虽然有一件奇怪的事情:在我的虚拟主机上它会创建 cookie.txt 而在我的本地主机上却没有。
- 为什么不在我的本地主机上创建一个 cookie?有什么建议么?具有相对路径和 wampserver 的东西?
以及后面的问题:
- 已经登录学校网站(存储 cookie 并因此保存 cURL 请求)是否有任何(速度)优势?
例如,我可以在第一个 cURL 请求之后检查响应中是否有证据表明我已经登录。
如果上述问题的答案是:'不,这不会使脚本更快'我还有一个问题:
- 最好只指定
CURLOPT_COOKIEFILE选项吗?有一个空值?所以没有饼干罐?
我不能给你我的登录信息,虽然这里是脚本:
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL,
'http://www.groenewoud.nl/infoweb/infoweb/index.php');
curl_setopt($curl, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt($curl, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
$tokenSource = curl_exec($curl);
print_r (curl_getinfo($curl));
if (!$tokenSource) echo 'token problem';
// Get the token from within the source codes of infoweb.
preg_match('/name="csrf" value="(.*?)"/', $tokenSource, $token);
$postFields = array(
'user' => $userNum,
'paswoord' => $userPass,
'login' => 'loginform',
'csrf' => $token[1]);
$postData = http_build_query($postFields);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, false);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
$tableSource = curl_exec($curl);
print_r( curl_getinfo($curl));
if (!$tableSource) echo 'post problem';
curl_close($curl);
【问题讨论】: