I have a very strange problem which I have been trying to figure out for 2 days, I have the below code to fetch information from a site for flight information, it works perfectly on my localhost and returns me "{thedata:what_I_Need}
" but when I upload the script on my server it returns an "{invalid:true}
" error from the site.
I tried it on 4 different droplets/vps, each in a different country IP with the same configuration (same curl-php-apache version and modules) as my local computer ( using ubuntu 14.4 with php5) but it still has the same issue. Here is the code which works perfectly on localhost:
$url = 'http://site.url.com';
$post = array(
'LanguageID' => 2,
'Trips' => array(array(
'Origin' => "JFK",
'Destination' => "TEX",
'Departure' => "2015-12-24T00:00:00",
)),
'Return' => "2015-12-28T00:00:00",
'Carriers' => null
'Adults' => 1,
'Children' => 0
);
$data_string = json_encode($post);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_string);
curl_setopt($ch,CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1");
curl_setopt($ch, CURLOPT_REFERER, "http://www.site.url.com");
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'X-Requested-With: XMLHttpRequest',
'Content-Length: ' . strlen($data_string))
);
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
$output=curl_exec($ch);
curl_close($ch);
I followed this article as well but I still have same issue on the remote site even if I replace CURLOPT_POST
with
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);