0

My code trying to call to a steam api JSON file will not output to a var_dump it just continues to say bool(false)

<?php
$steamkey = "removed";
$id_user = '76561198059606697';

$apifr = "http://a...content-available-to-author-only...d.com/ISteamUser/GetPlayerSummaries/v0002/?key=".$steamkey."&steamids=".$id_user."";

print("(test) JSON File : $apifr"); 

$ch = curl_init();

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_URL,$apifr);

$result=curl_exec($ch);
var_dump($result);
curl_close($ch);

?>

I'm not sure how to use CURL and I don't know whats going wrong here.

Rain Drops
  • 31
  • 1
  • 6
  • ideone.com/TV0Y0L -- Code here showing bool error – Rain Drops Dec 09 '16 at 01:23
  • That means the curl request is failing. – Barmar Dec 09 '16 at 01:25
  • How do you expect it to work in ideone.com when you have a fake URL? – Barmar Dec 09 '16 at 01:26
  • I'm not sure what about it is failing, I have something printing "apifr" when I had my key I could copy exactly from the console and the url would open the JSON – Rain Drops Dec 09 '16 at 01:26
  • Use `echo curl_error($ch);` to see the reason why it's failing. – Barmar Dec 09 '16 at 01:27
  • It prints "Could not resolve host: www.api.steampowered.com" What would I do to fix this if anything? – Rain Drops Dec 09 '16 at 01:29
  • It should just be `api.steampowered.com`, not `www.api.steampowered.com` – Barmar Dec 09 '16 at 01:29
  • I only added that to test it, It said the same with just http:// – Rain Drops Dec 09 '16 at 01:30
  • What error do you get when you use the correct hostname? – Barmar Dec 09 '16 at 01:31
  • "Could not resolve host: api.steampowered.com" – Rain Drops Dec 09 '16 at 01:31
  • Then there's a problem with the DNS on the machine you're running the script on, because that name resolves fine for me. – Barmar Dec 09 '16 at 01:32
  • I just ran the same code on my other machine ( I could understand if this laptop is a bit weird) but I still got the same issue. Is it possible that its an ideone issue? Even when ran on my host it says " couldn't connect to host " – Rain Drops Dec 09 '16 at 01:36
  • I think ideone.com is blocking network access. I tried my company's URL and it also failed. But when I ran the same script on my local machine, it worked. – Barmar Dec 09 '16 at 01:43
  • I also tried your original script on my machine and it worked. – Barmar Dec 09 '16 at 01:44
  • They probably don't want people using their server to launch attacks on other sites, so they block DNS and cURL. – Barmar Dec 09 '16 at 01:45
  • I ran it locally and the code you provided is absolutely fine and working. – Robbie Dec 09 '16 at 01:46
  • I guess my host is blocking CURL as well. That might explain the majority of my errors today. after looking into it, it seems thats the issue. Thank you for the help! – Rain Drops Dec 09 '16 at 01:46
  • Shared hosts blocking external access is not unheard of; but often they will open it up for you if you ask (IME at least). So now that's sorted, I suggest you remove your steam key from the example. – Robbie Dec 09 '16 at 01:49

1 Answers1

0

It ended up being an issue with my host. Thanks for all the help -resolved

Rain Drops
  • 31
  • 1
  • 6