Connecting Tech Pros Worldwide Forums | Help | Site Map

Sending a User-Agent header

jx2 jx2 is offline
Familiar Sight
 
Join Date: Feb 2007
Location: Bristol UK
Posts: 227
#1: Aug 23 '07
i just try it it works for bbc site
your server might not allow you openning anything out of your root folder
especialy if your site is hosted
[php]
$a = file("http://www.bbc.co.uk");
$a = implode($a);

echo htmlentities($a);

[/php]
LOL they recognize browser and sent me WAP like formated page

any one know how to pretend tha PHP is IE?

regards
jx2

pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#2: Aug 23 '07

re: Sending a User-Agent header


Heya, JX2.

To do that, you'll need to either create an HTTP stream context or else use cURL so that you can set the User-Agent header.
jx2 jx2 is offline
Familiar Sight
 
Join Date: Feb 2007
Location: Bristol UK
Posts: 227
#3: Aug 23 '07

re: Sending a User-Agent header


Quote:

Originally Posted by pbmods

Heya, JX2.

To do that, you'll need to either create an HTTP stream context or else use cURL so that you can set the User-Agent header.

sorry to ask you - have you got simply handy example ? you know something to start with...
thx

wow something moved i didnt know i started new post :-)
pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#4: Aug 23 '07

re: Sending a User-Agent header


Heya, JX2.

I went ahead and split these posts into their own thread so as to avoid hijacking NewLearner's thread.

Here's a basic example:
Expand|Select|Wrap|Line Numbers
  1. $context = stream_context_create(array('http' => array(
  2.     'method'    => 'get',
  3.     'header'    => 'User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/522.11.1 (KHTML, like Gecko) Version/3.0.3 Safari/522.12.1'
  4. )));
  5.  
  6. $data = file_get_contents($url, $context);
  7.  
This code will send the User-Agent header with the HTTP GET request.

For more information, check out this document.
jx2 jx2 is offline
Familiar Sight
 
Join Date: Feb 2007
Location: Bristol UK
Posts: 227
#5: Aug 23 '07

re: Sending a User-Agent header


Expand|Select|Wrap|Line Numbers
  1. $context = stream_context_create(array('http' => array(
  2.     'method'    => 'get',
  3.     'header'    => 'User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/522.11.1 (KHTML, like Gecko) Version/3.0.3 Safari/522.12.1'
  4. )));
  5.  
  6. $fp = fopen($url,false,$context);
  7. fpasthrou($fp);
  8.  
as usually you are the man!!
Reply