burnsj2
asked on
PHP set User Agent String
I'm working on a project where the API requires that I "must set the HTTP user agent to a valid web browser string" like Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
My questions is, how do I actually "set" the user agent in PHP. Can it be done with header()?
The actual call to the API looks like $xml = simplexml_load_file($url);
Thanks.
My questions is, how do I actually "set" the user agent in PHP. Can it be done with header()?
The actual call to the API looks like $xml = simplexml_load_file($url);
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It seems the trick is to use:
ini_set("user_agent","Mozi lla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
in your PHP document. The "user_agent" is a setting in php.ini and is set to "PHP" by default.
ini_set("user_agent","Mozi
in your PHP document. The "user_agent" is a setting in php.ini and is set to "PHP" by default.
You should be more specific of what you needed it for next time. you have three different reponses, and they're all relavant. Personally, I think you should give us all points because you didn't say what you needed to change the user-agent for.
I'm just looking out for every one else. :)
I'm just looking out for every one else. :)
Thanks for the lookout, Oscurochu.
I must say though, your solution was more thorough.
I must say though, your solution was more thorough.
ASKER
Just as a note, neither solution worked in my case, but if using sockets Oscurochu's would pass a user agent to another server, the first solution would change the user agent of the client calling the script.
<?php
print $_SERVER['HTTP_USER_AGENT'
$_SERVER['HTTP_USER_AGENT'
print "<br />";
print $_SERVER['HTTP_USER_AGENT'
?>