Set the User Agent With PHP cURL
A few months back, I shared with you how to download the contents of a URL and execute a HTTP POST transmission using PHP cURL. For security purposes, some hosts require that a common user agent be present in the POST. If an unacceptable user agent is given, the POST is ignored. Luckily, cURL allows us to "spoof" the server using any user agent we choose:
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
A little sneaky but it could get you out of a jam at some point!
CSS animations are a lot of fun; the beauty of them is that through many simple properties, you can create anything from an elegant fade in to a WTF-Pixar-would-be-proud effect. One CSS effect somewhere in between is the CSS flip effect, whereby there's...
CSS and JavaScript: the lines seemingly get blurred by each browser release. They have always done a very different job but in the end they are both front-end technologies so they need do need to work closely. We have our .js files and our .css, but...
Remember the Web 1.0 days where you had to customize your site in every way possible? You abused the scrollbars in Internet Explorer, of course, but the most popular external service I can remember was CometCursor. CometCursor let you create and use loads of custom cursors for...
Thanks for this tip. Was working on a project and found your tip very handy.
Thanks for this! Was needed for a wikipedia curl request.
Thanks for this, it for me too.
hi..
How to check whether a user agent string is supported by all the urls or not ? I have tried many urls with different user agent strings but I couldn’t find any user agent which is supported by all urls. When a user agent string is not supported, I get 0 (zero) as http response code and null as mime type. Please help.
Thanks, without setting user agent I was getting this error:
at
nl.bitwalker.useragentutils.Browser.isInUserAgentString(Browser.java:154)
“for security purposes”… that’s incredibly weak security. I think it’s more common for the website to be doing useragent sniffing (to tailor the response to the browser), and simply not bothering to support uncommon useragents.
perfect – thank for the tip!
Thank, that helped!
i get error code like this.
curl_setopt()
expects parameter 1 to be resource,null
given in/home/xxxx/xxxxx
Try this…
You are getting the error as
curl_setopt()
required first parameter as a resource returned by thecurl_init($url)
;This, in fact, just got me out of a jam.
Almost a full 10 years later and this post just really helped me out! Thanks!