Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set user agent for get_headers PHP function

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.

like image 840
Farhad Avatar asked Dec 06 '11 16:12

Farhad


2 Answers

Maybe this?

ini_set('user_agent', 'Mozilla/5.0');
like image 86
ioseb Avatar answered Nov 09 '22 13:11

ioseb


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
like image 21
Jonathan Rich Avatar answered Nov 09 '22 12:11

Jonathan Rich