在php中使用readfile()读取远程文件时是否可以设置User-Agent? [英] Is it possible to set a User-Agent when reading a remote file using readfile() in php?
本文介绍了在php中使用readfile()读取远程文件时是否可以设置User-Agent?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如,在cURL中,我可以使用 curl_setopt($ curlrequest,CURLOPT_USERAGENT,'myuseragent');
来更改用户代理
当我请求 $ curlrequest
中指定的页面时。
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
.
但我可以用 readfile()
做类似的事情?
But can I do something similar with readfile()
?
推荐答案
是的,你可以在 php.ini
配置文件中设置 user_agent
属性,或者通过 ini_set()
在运行时。
Yes, you can set a user_agent
property in your php.ini
config file or via ini_set()
at runtime.
参见 http://php.net/manual/en/filesystem.configuration.php#ini.user-agent (通过 http://php.net/manual/en/wrappers.http.php )
示例(根据要求)
ini_set('user_agent', 'RTM');
这篇关于在php中使用readfile()读取远程文件时是否可以设置User-Agent?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文