For example, in cURL I can use curl_setopt($curlrequest, CURLOPT_USERAGENT, 'myuseragent');
in order to change the User-Agent
when I'm requesting the page specified in $curlrequest
.
But can I do something similar with readfile()
?
For example, in cURL I can use curl_setopt($curlrequest, CURLOPT_USERAGENT, 'myuseragent');
in order to change the User-Agent
when I'm requesting the page specified in $curlrequest
.
But can I do something similar with readfile()
?
Yes, you can set a user_agent
property in your php.ini
config file or via ini_set()
at runtime.
See http://php.net/manual/en/filesystem.configuration.php#ini.user-agent (via http://php.net/manual/en/wrappers.http.php)
An example (as requested)
ini_set('user_agent', 'RTM');
You can set the user_agent
property in the php.ini config file, or use ini_set to change it without modifying the php.ini, so you can customize on a per-script basis.
Also, one of the comments from this page says you can do something like this:
<?php
$default_opts = array(
'http' => array(
'user_agent' => 'Foobar',
'header' => array(
'X-Foo: Bar',
'X-Bar: Baz'
)
)
);
stream_context_get_default($default_opts);
readfile('http://www.xhaus.com/headers');
?>