Skip to content
Advertisement

How to disguise your PHP script as a browser?

We’ve been using information from a site for a while now (something that the site allows if you mention the source and we do) and we’ve been copying the information by hand. As you could imagine this can become tedious pretty fast so I’ve been trying to automate the process by fetching the information with a PHP script.

The URL I’m trying to fetch is:

JavaScript

If I enter it in a browser it works, if I try a file_get_contents() I get Bad Request

I figured that they checked to see if the client is a browser so I rolled a CURL based solution:

JavaScript

I’ve checked and the headers are identical with my browser’s headers and I still get Bad Request

So I tried another solution:

JavaScript

Unfortunately this doesn’t work either and I’m out of ideas. What am I missing?

Advertisement

Answer

Try escaping your URL, it works for me that way.

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement