-2

Very simple code in PHP, that looks like this:

curl_setopt($ch, CURLOPT_URL, "http://[heres url]");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('keycode: [heres keycode]'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$output = curl_exec($ch);
curl_close($ch);

var_dump(json_decode($output, true));
// echo $output; doesn't work as well

[heres url], [heres keycode] - url and keycode are correct

If I run the same script in a app (for example I am using a chrome app named Advanced REST Client) - everything works.

In my PHP script the result is either empty or NULL.

What could be the problem? Thanks.

Paul G
  • 1

1 Answers1

0
    $url='https://randomuser.me/api/';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_VERBOSE, 0);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION , 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_HTTPHEADER,array('keycode: [here value]'));
    curl_setopt($ch, CURLOPT_URL,$url);
    $html = curl_exec($ch);
    var_dump(json_decode($html, true));
F5 Buddy
  • 474
  • 4
  • 4