This question has already been answered:

With cURLa poking on the XML page. If this page does not exist, then it redirects to a beautifully designed 404 page. As a result, SimpleXML gives an error that the XML is invalid. Question: how to determine that cURL received a 404 page, and not an XML file? Or maybe there is some other way ..?

I attach the code:

$ch = curl_init($xml_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $xml_page = curl_exec($ch); curl_close($ch); 

Thank.

Reported as a duplicate by participants of Vadim Ovchinnikov , AK , Community Spirit Jan 8 '17 at 17:01 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • Yeah. Thank. But it didn’t really help, as it’s poked on the 200 OK code. I will then use the parser to determine the presence of certain parameters to determine the valid XML. - Leah Hael

1 answer 1

Set the option for CURLOPT_FOLLOWLOCATION=false and it will not be redirected if it is really a redirect.

  • A little bit wrong. But thanks. Information is useful. - Leah Hael