Tom
Tom

Reputation: 1651

PHP: Can CURL follow meta redirects

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

Thanks

Upvotes: 3

Views: 7750

Answers (1)

Dominic Rodger
Dominic Rodger

Reputation: 99801

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

Upvotes: 15

Related Questions