Search code examples
phpjsonfile-get-contents

How does IPinfo show json data using file_get_contents


Today I was using an api for getting information for a specific IP address and it works fine.

file_get_contents("https://ipinfo.io/172.217.19.206");

From this I get normal json output which I can json_decode

{ "ip": "172.217.19.206", "hostname": "ams16s31-in-f14.1e100.net", "city": "", "region": "", "country": "US", "loc": "37.7510,-97.8220", "org": "AS15169 Google LLC" }

But the thing that I do not understand is if I visit the page https://ipinfo.io/172.217.19.206 using the browser then I do not see this output at all. I always thought file_get_contents gets the source of the page?


Solution

  • This website used useragent method for handling this.

    You can test it by Postman.

    Only set null value for User-Agent in Headers section and send get request to that url.

    Postman Example