PHP cURL: Get target of redirect, without following it

前端 未结 5 1334
梦毁少年i
梦毁少年i 2021-01-02 10:47

The curl_getinfo function returns a lot of metadata about the result of an HTTP request. However, for some reason it doesn\'t include the bit of information I want at the m

5条回答
  •  南笙
    南笙 (楼主)
    2021-01-02 10:54

    I had the same problem and curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); was of any help.

    So, I decided not to use CURL but file_get_contents instead:

    $data = file_get_contents($url);
    $data = str_replace("

    The last line helped me to block the redirection although the product is not a clean html code.

    I parsed the data and could retrieve the redirection URL I wanted to get.

提交回复
热议问题