I try to curl this url and this is curl cmd command using copy as curl in chrome :
curl "http://b2b.sriwijayaair.co.id/SJ-Eticket/login.php?action=in" -H "Pragma: no-cache" -H "Accept-Encoding: gzip, deflate, sdch" -H "Accept-Language: en-US,en;q=0.8" -H "Upgrade-Insecure-Requests: 1" -H "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" -H "Cache-Control: no-cache" -H "Cookie: PHPSESSID=nupsnjthtmgedjcuguh80667v4; _ga=GA1.3.1626934475.1455171426" -H "Connection: keep-alive" --compressed
I got the results i expected when using cmd, but when i try convert to php the result is not same
PHP Code :
$curl = curl_init();
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1');
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Pragma: no-cache',
'Accept-Encoding: gzip, deflate, sdch',
'Accept-Language: en-US,en;q=0.8',
'Upgrade-Insecure-Requests: 1',
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Cache-Control: no-cache',
'Cookie: PHPSESSID=nupsnjthtmgedjcuguh80667v4; _ga=GA1.3.1626934475.1455171426'
));
curl_setopt($curl, CURLOPT_URL, 'http://b2b.sriwijayaair.co.id/SJ-Eticket/login.php?action=in');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
$result = curl_exec($curl);
curl_close($curl);
print_r($result);
What i miss ?
You don't need to send all the headers as chrome does.
Also you are missing cookie in your header. Try with this header.
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Cookie: PHPSESSID=nupsnjthtmgedjcuguh80667v4; _ga=GA1.3.1626934475.1455171426'
));
Note: This cookie you have copied from your browser. So it will expire soon.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.