2

CURL gives HTTP/1.1 302 Moved Temporarily

$ua = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.A.B.C Safari/525.13';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://...........");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $ua);
curl_setopt($ch1, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch1, CURLOPT_POST, true);
curl_setopt($ch1, CURLOPT_HTTPHEADER, array('Accept: Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11'));
$result = curl_exec($ch1);

Output:

HTTP/1.1 302 Moved Temporarily Content-Length: 0 Connection: keep-alive Date: Mon, 03 Jul 2017 12:23:55 GMT Set-Cookie:AWSALB=ZBxF0OO7JHWtHtsbAUVLo1a2Y7GQ1KTxIaMml+1UFTDK2UL7V6Xm8FIU1mWeCDZDtYvQ0emHLPLOtWpli +6pqFbYe+ulWPA8SBqeM/n5S9x0ScxYTGVsUeDixyuf; Expires=Mon, 10 Jul 2017 12:23:55 GMT; Path=/ Server: nginx/1.8.0 Location: https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx X-Cache: Miss from cloudfront Via: 1.1 ea5d711fdce750991b725e09c07704b0.cloudfront.net (CloudFront) X-Amz-Cf-Id: rVytkGKHVM628Zh3WFSohHlVdb-6XXZX-cXlQkvtRSeDCZN95s9Guw==

chris85
  • 23,846
  • 7
  • 34
  • 51
Nimesh Patel
  • 293
  • 1
  • 11
  • 1
    Set `CURLOPT_FOLLOWLOCATION` to true if you want to follow redirects – apokryfos Jul 03 '17 at 13:03
  • 1
    Possible duplicate of [Make curl follow redirects?](https://stackoverflow.com/questions/3519939/make-curl-follow-redirects) – chris85 Jul 03 '17 at 13:05
  • i have already used but same result – Nimesh Patel Jul 03 '17 at 13:06
  • You used `CURLOPT_FOLLOWLOCATION, false` FALSE means dont follow. `TRUE to follow any "Location: " header that the server sends as part of the HTTP header (note this is recursive, PHP will follow as many "Location: " headers that it is sent, unless CURLOPT_MAXREDIRS is set).` -http://php.net/manual/en/function.curl-setopt.php – chris85 Jul 03 '17 at 13:07
  • If i am going to set curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); then it gives **"HTTP/1.1 403 Forbidden"** after **HTTP/1.1 302 Moved Temporarily** – Nimesh Patel Jul 03 '17 at 13:13
  • The answer to the question you asked though is the dup. You should update the code and the question in that case. – chris85 Jul 03 '17 at 13:19

0 Answers0