I am developing php application with cURL library.
I would like to get redirect url (in case 301 or 302 http code). In Windows it is simple, I just need to call curl_getinfo($ch). This methods returns associative array with redirect_url, which I am using later.
I have problem when I moved my application to linux server. Such method (curl_getinfo) returns array too, but there is no "redirect_url" index. I though I could try to read headers as a string. I set
curl_setopt(CURLOPT_HEADERFUNCTION, callback) and save response headers as a string. Then I use simple parser to get fields I am interested in. But now I have another problem. Redirect url (http header LOCATION) returns relative url (whereas in Windows it is absolute).
Why there are differences in windows cURL and linux one? What can I do to make this application resistant to OS changes? And finally, how can I get this field (redirect url) as an absolute url in linux.
Thanks for your help :)
Sample from Windows:
Array ( [url] => http:// wiadomosci.wp.pl/kat,1342,title,Ciag-dalszy-sporu-wokol-poslow-PiS-Nie-moge-tego-zrobic,wid,13927471,wiadomosc.html [content_type] => text/html [http_code] => 302 [header_size] => 2407 [request_size] => 384 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.046 [namelookup_time] => 0 [connect_time] => 0.015 [pretransfer_time] => 0.015 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => 0 [upload_content_length] => 0 [starttransfer_time] => 0.046 [redirect_time] => 0 [certinfo] => Array ( ) [redirect_url] => http:// wiadomosci.wp.pl/kat,1342,title,Ciag-dalszy-sporu-wokol- poslow-PiS-Nie-moge-tego-zrobic,wid,13927471,wiadomosc.html?ticaid=1d436 ) and windows:
Array ( [url] => http:// wiadomosci.wp.pl/kat,1342,title,Ciag-dalszy-sporu-wokol-poslow-PiS-Nie-moge-tego-zrobic,wid,13927471,wiadomosc.html [content_type] => text/html [http_code] => 302 [header_size] => 2425 [request_size] => 384 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.023254 [namelookup_time] => 0.001938 [connect_time] => 0.004836 [pretransfer_time] => 0.004847 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => 0 [upload_content_length] => 0 [starttransfer_time] => 0.023068 [redirect_time] => 0 [certinfo] => Array ( ) )
Redirect url (http header LOCATION) returns relative url (whereas in Windows it is absolute).: That is the server, not cURL. The server is sending a relative URL - which is a protocol violation, but everybody does it anyway, so you have to be able to handle it. The cURL library should be the same in Windows and Linux (and any other environment), but may behave differently across PHP/library versions - are you running a newer version of PHP/cURL library on Windows than you are on Linux?