PHP: Can CURL follow meta redirects

前端 未结 1 1188
迷失自我
迷失自我 2020-12-02 02:38

CURL can follow header redirects with the use of CURLOPT_FOLLOWLOCATION but is it possible to follow meta refresh redirects?

Thanks

相关标签:
1条回答
  • 2020-12-02 02:55

    Yes, but you'll have to do it yourself by parsing the response and looking for things that look like:

    <meta http-equiv="refresh" content="5;url=http://example.com/" />
    

    Obeying <meta> refresh requests is a browser-side thing. Use DOM parsing to look for <meta> tags with the appropriate attributes in the response cURL gives you.

    If you can guarantee that the response is valid XML, you could do something like this:

    $xml = simplexml_load_file($cURLResponse);
    $result = $xml->xpath("//meta[@http-equiv='refresh']");
    // Process the $result element to get the relevant bit out of the content attribute
    
    0 讨论(0)
提交回复
热议问题