Set cURL to use local virtual hosts

Actually, curl has an option explicitly for this: –resolve Instead of curl -H ‘Host: yada.com’ http://127.0.0.1/something use curl –resolve ‘yada.com:80:127.0.0.1′ http://yada.com/something What’s the difference, you ask? Among others, this works with HTTPS. Assuming your local server has a certificate for yada.com, the first example above will fail because the yada.com certificate doesn’t match the 127.0.0.1 … Read more

CURLOPT_FOLLOWLOCATION cannot be activated [duplicate]

Set safe_mode = Off in your php.ini file (it’s usually in /etc/ on the server). If that’s already off, then look around for the open_basedir stuff in the php.ini file, and change it accordingly. Basically, the follow location option has been disabled as a security measure, but PHP’s built-in security features are usually more annoying … Read more

How to display request headers with command line curl

curl’s -v or –verbose option shows the HTTP request headers, among other things. Here is some sample output: $ curl -v http://google.com/ * About to connect() to google.com port 80 (#0) * Trying 66.102.7.104… connected * Connected to google.com (66.102.7.104) port 80 (#0) > GET / HTTP/1.1 > User-Agent: curl/7.16.4 (i386-apple-darwin9.0) libcurl/7.16.4 OpenSSL/0.9.7l zlib/1.2.3 > … Read more

curl follow location error

The workaround is to implement redirection in PHP code. Here is my own implementation. It has two known limitations: It will force CURLOPT_RETURNTRANSFER It is incompatible with CURLOPT_HEADERFUNCTION The code: function curl_exec_follow(/*resource*/ &$ch, /*int*/ $redirects = 20, /*bool*/ $curlopt_header = false) { if ((!ini_get(‘open_basedir’) && !ini_get(‘safe_mode’)) || $redirects < 1) { curl_setopt($ch, CURLOPT_HEADER, $curlopt_header); curl_setopt($ch, … Read more