我正在使用github的php-curl-class。
我已经发送了一些帖子以使用$curl->post("webiste.com", array());
登录网站,从响应中返回数据后,我可以验证我已成功登录。
我的问题在于使用$curl->get("http://website.com");
时。
PHP cURL 类的 get() 函数没有正确读取 cookie。
我的代码在文档顶部包含以下内容:
$curl = new Curl();
$curl->setCookieFile('cookies.txt');
$curl->setCookieJar('cookies.txt');
这还不足以让 get() 函数正确使用 cookie 吗?
我可以验证 cookie.txt 文件是否已创建并且 cookie 打印在文件中,但它们只是没有 100% 使用。
我知道它们没有被正确读取,因为当我使用以下代码时:
echo $curl->get("website.com");
我可以看到我没有登录。
我已经解决了这个问题。
所以我补充说
$curl->setCookieFile('cookies.txt');
$curl->setCookieJar('cookies.txt');
在函数内部,我试图使用
$curl->get();
函数之外。而且我只在函数中设置了 cookiejar 和 cookiefile,所以在 $curl->get() 之前;函数,我需要重新声明 cookiefile 和 jar。