PHP: Can CURL follow a meta redirect?

CURL can follow header forwarding using CURLOPT_FOLLOWLOCATION, but is it possible to follow meta-update forwarding?

thanks

+3
source share
1 answer

Yes, but you have to do it yourself by analyzing the answer and finding things that look like this:

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

Fulfilling <meta> requests for updates is a browser business. Use DOM parsing to search for <meta> tags with matching attributes in the cURL response.

If you can guarantee that the response is valid XML, you can 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 
+15
source

Source: https://habr.com/ru/post/1380845/


All Articles