Sunday, October 7, 2012

PHP Curl UserAgent.

I had a unique problem this weekend, while working on my pet project. I had a URL which when pasted in the browser, i got the data. However, when I provided the same URL in PHP and tried to pull the data through CURL I was unable to get any data. 

First thing that came to my mind was to set the "useragent" i.e to fool the webserver that the request is through a browser. And it worked like a charm.

Following is the curl option that i had to set:

    curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.7) Gecko/20100101 Firefox/10.0.7');

Regards,
Sri

No comments:

Post a Comment