1

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
  • Am trying trying to understand what you want to achieve Commented Sep 12, 2012 at 17:51

1 Answer 1

1

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');

?>

Sign up to request clarification or add additional context in comments.

2 Comments

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'); ?>
You can use $_SERVER['HTTP_USER_AGENT'] to get the user agent sent by user browser

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.