I'm trying to get some DOM from external URLs while passing some headers, so the received DOM must be different depending on them.
For instance, if I have a mobile device header, the received DOM should be completely different than from a PC header.
At the moment I haven't found the way to do this, as I'm always receiving the same DOM (with my default headers).
Thank you in advance.
You can specify a so called stream context for the load operation. Check this example, which is derived from the PHP manual
// Specify headers
$opts = array(
'http' => array(
'user_agent' => 'PHP libxml agent',
)
);
// Create and assign a stream context
$context = stream_context_create($opts);
libxml_set_streams_context($context);
// request the HTML file through HTTP
$doc = DOMDocument::loadHTMLFile('http://www.example.com/file.html');
You can follow theses articles in the PHP manual: