Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我知道为 curl 设置用户代理很容易,但我的代码基于 get_headers,默认情况下 get_headers 用户代理为空。谢谢你的帮助。
也许这个?
ini_set('user_agent', 'Mozilla/5.0');
get_headers 仅指定服务器发送给客户端(在本例中为 PHP)的数据,它不指定请求标头。
如果您尝试查找发出 get_headers 请求的用户代理,则必须使用:
ini_get('user_agent');
有关更多文档,请参见以下链接: