how to set user agent for get_headers PHP function

六月ゝ 毕业季﹏ 提交于 2019-12-10 13:26:23

问题


I know It's easy to set user agent for curl but my code is based on get_headers, by default get_headers user agent is empty. thanks for any help.


回答1:


Maybe this?

ini_set('user_agent', 'Mozilla/5.0');



回答2:


get_headers only specifies the data sent by the server to the client (in this case, PHP), it doesn't specify request headers.

If you're trying to find the user agent the get_headers request was made with, you'll have to use:

ini_get('user_agent');

For more documentation see the links below:

  • http://us3.php.net/get_headers
  • http://us3.php.net/manual/en/filesystem.configuration.php#ini.user-agent


来源:https://stackoverflow.com/questions/8403025/how-to-set-user-agent-for-get-headers-php-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!