I got this error message:
CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set in.
safe_mode i
Just a note:
All answers with code here manually parse the headers from a curl request to find a Location:
header.
However, since PHP 5.3.7, there is an option CURLINFO_REDIRECT_URL
you can use with curl_getinfo()
. No need to do requests twice, no need to enable headers if you don't want them, no need for regexps.