It is possible that the web application at sub.example.com
expects some additional input apart from what goes into the URL (e.g. a cookie), does not find this input, and errors out.
In any case, it's certain that the HTTP requests generated by (a) your program and (b) your browser are not identical, otherwise the application would exhibit the same behavior in both cases.
To debug this, you can do the following:
- Rewrite the code to use
cURL
instead of file_get_contents
, so that you can specify an HTTP proxy
- Install Fiddler, a fantastic HTTP debugging proxy
- Pass the HTTP request your application generates and one given manually through the browser through Fiddler
- Find the differences (you can simply do a text compare on the requests), this will lead you to the answer