php cURL doesn't follow redirect -
i use following code http-status code of final url (after following redirects):
$handle = curl_init($url); curl_setopt($handle, curlopt_followlocation, true); curl_setopt($handle, curlopt_returntransfer, true); curl_setopt($handle, curlopt_header, true); // want headers //curl_setopt($handle, curlopt_nobody, true); curl_setopt($handle, curlopt_timeout, 5); curl_setopt($handle, curlopt_ssl_verifypeer, false); curl_setopt($handle, curlopt_useragent, 'my bot'); $response = curl_exec($handle); $httpcode = curl_getinfo($handle, curlinfo_http_code); curl_close($handle);
however, curl doesn't follow redirects. f.e. if use www.raffiniert.biz/kunden, shows plain 301, instead of following www.raffiniert.biz/kunden/
what's wrong?
thanks raphael
i got expected response using same code.
http/1.1 301 moved permanently server: nginx date: mon, 01 dec 2014 23:19:56 gmt content-type: text/html; charset=iso-8859-1 content-length: 309 connection: keep-alive location: http://www.raffiniert.biz/kunden/ cache-control: max-age=0 expires: mon, 01 dec 2014 23:19:56 gmt vary: accept-encoding http/1.1 403 forbidden server: nginx date: mon, 01 dec 2014 23:19:57 gmt content-type: text/html; charset=iso-8859-1 content-length: 277 connection: keep-alive vary: accept-encoding <!doctype html public "-//ietf//dtd html 2.0//en"> <html><head> <title>403 forbidden</title> </head><body> <h1>forbidden</h1> <p>you don't have permission access /kunden/ on server.</p> <hr> <address>apache server @ www.raffiniert.biz port 80</address> </body></html>
you have check...
error_reporting(-1);
or
if (ini_get('safe_mode') || (string)ini_get('open_basedir') !== '') { exit('you have no permission set curlopt_followlocation'); }
Comments
Post a Comment