cannot use cookies in cURL PHP

madelinecrane

New Member
I'm using cURL to parse a website. \[quote\] http://www.hcmiu.edu.vn/bookforsale/showbooks.php\[/quote\]It need session to view, if you don't have session then the page redirect to :\[quote\] http://www.hcmiu.edu.vn/bookforsale/perInfo.php\[/quote\]I use this code to get session cookie but I don't know why I cannot see any change to file cookies.txt\[code\]$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 = http://stackoverflow.com/questions/3852750/curl_exec($ch);$file = fopen("example.txt", "w");fwrite($file, $returnData);fclose($file);curl_close($ch);\[/code\]However, I see:\[code\]Set-Cookie: PHPSESSID=1egb993objkrdp3gi5mpvs02g0; path=/ \[/code\]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 .
 
Back
Top