I'm using cURL to parse a website.
It need session to view, if you don't have session then the page redirect to :
I use this code to get session cookie but I don't know why I cannot see any change to file cookies.txt
$urltopost = "http://www.hcmiu.edu.vn/bookforsale/perInfo.php";
$datatopost = array (
"name" => "abc",
"tel" => "99999999",
"email" => "[email protected]",
"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);
However, I see:
Set-Cookie: PHPSESSID=1egb993objkrdp3gi5mpvs02g0; path=/
in the header. Thanks for any help
-Edit: I use a tricky way: I use http viewer to view the PHPSESSID in browser cookies. And then I use it to to create a cookies file for cURL to read. Then I could pass the session checking of the web server for viewing file showbooks.php .