How to add User Agent in PHP Simple HTML DOM Parser, so that it will browse a website with each user agent for every visitor with his / her ip address. Any example or idea.. Thanks
1 Answer
You can set the user agent in the option of stream context
<?php
$opts = array(
'http' => array(
'user_agent' => 'Enter agent here',
)
);
$context = stream_context_create($opts);
libxml_set_streams_context($context);
$doc = DOMDocument::load('URL');
?>
2 Comments
HasanTG
thats cool.. but is there any way to get User agent first from each user and then post it here suppose,
$user_agent = 'here we will collect a user info and then announce it in a variable'; so your code should like this> <?php $opts = array( 'http' => array( 'user_agent' => '$user_agent', ) ); $context = stream_context_create($opts); libxml_set_streams_context($context); $doc = DOMDocument::load('URL'); ?> Tarun
You can use $_SERVER['HTTP_USER_AGENT'] to get the user agent sent by user browser