PHP cURL redirects to localhost

只谈情不闲聊 提交于 2019-12-01 14:40:55
Floris

Answering part of your question:

From http://php.net/manual/en/function.curl-setopt.php :

CURLOPT_RETURNTRANSFER TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.

In other words - doing exactly what you described. It's returning the response to a string and you echo it to see it. As requested...

----- EDIT-----

As for the second part of your question - when I change the last three lines of the script to

$output = curl_exec($ch);
header('Location:'.$website);
echo $output;

The address of the page as displayed changes to $website - which in my case is the variable I use to store my equivalent of your 'https://www.websiteurl.com/login'

I am not sure that is what you wanted to do - because I'm not sure I understand what your next steps are. If you were getting redirected by the login site, wouldn't the new address be part of the header that is returned? And wouldn't you need to extract that address in order to perform the next request (wget or whatever) in order to download the file you wanted to get?

To do so, you need to set CURLOPT_HEADER to TRUE,

You can get the URL where you ended up from

$last_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); 

(see cURL , get redirect url to a variable ).

The same link also has a useful script for completely parsing the header information (returned when CURLOPT_HEADER==true. It's in the answer by nico limpica.

Bottom line: CURL gets the information that your browser would have received if you had pointed it to a particular site; that doesn't mean your browser behaves as though you pointed it to that site...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!