If you're using cURL, you can use curl_setopt ($handle, CURLOPT_USERAGENT, 'browser description')
to define the user-agent header of the request.
If you're using file_get_contents
, check out this tweak of an example on the man page for file_get_contents:
// Create a stream
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-language: en
" .
"Cookie: foo=bar
" .
"User-agent: BROWSER-DESCRIPTION-HERE
"
)
);
$context = stream_context_create($opts);
// Open the file using the HTTP headers set above
$file = file_get_contents('http://www.example.com/', false, $context);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…