我正在使用 cURL 来解析网站。
它需要会话才能查看,如果您没有会话,则页面重定向到:
我使用此代码获取会话 cookie,但我不知道为什么我看不到文件 cookies.txt 的任何更改
$urltopost = "http://www.hcmiu.edu.vn/bookforsale/perInfo.php";
$datatopost = array (
"name" => "abc",
"tel" => "99999999",
"email" => "abc@gmail.com",
"profession" => "abc",
"employer" => "abc",
"tel_work" => "99999999",
);
$ch = curl_init($urltopost);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $datatopost);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/cookies.txt");
$returnData = curl_exec($ch);
$file = fopen("example.txt", "w");
fwrite($file, $returnData);
fclose($file);
curl_close($ch);
但是,我看到:
Set-Cookie: PHPSESSID=1egb993objkrdp3gi5mpvs02g0; path=/
在标题中。谢谢你的帮助
-编辑:我使用了一个棘手的方法:我使用 http 查看器查看浏览器 cookie 中的 PHPSESSID。然后我用它来创建一个 cookie 文件供 cURL 读取。然后我可以通过 web 服务器的会话检查来查看文件 showbooks.php 。