Secret User Agent Man!

I was creating a PHP helper class to leverage the NPS Data API recently, and stumbled across an odd situation where I could successfully retrieve the API’s JSON result in Google Chrome with the ModHeader extension— but PHP’s file_get_contents function would fail with a Server 500 error.

After several  Google searches, I stumbled across this post on Stack Overflow which got to the heart of the problem. It turns out PHP’s default user agent string for file_get_results is blank, and some web servers are configured to ignore requests with empty user agent strings. Once I added an Agent String in my PHP’s header request, it started to return results as expected.