I'm wondering if anyone can help me with this problem I have.
I'm working on a script and I need to be able to detect the browser that is being used in PHP. I can't use 'HTTP_USER_AGENT' because for some reason it's not available on the server we have. Now, the odd thing is that we are on a dedicated server and register globals is set to on, but that's a different matter.
I was wondering if anybody had found a solution to this for servers where register globals is set to off (or similar). All help would be greatly appreciated as it's becoming a little urgent now.
Detecting Browsers with registered globals set to off
Moderator: General Moderators
-
SteveMellor
- Forum Commoner
- Posts: 25
- Joined: Mon Jun 26, 2006 7:43 am
- stereofrog
- Forum Contributor
- Posts: 386
- Joined: Mon Dec 04, 2006 6:10 am
What does this say?
Code: Select all
print_r($_SERVER);-
SteveMellor
- Forum Commoner
- Posts: 25
- Joined: Mon Jun 26, 2006 7:43 am
Interestingly is says the following, which wasn't working before.
I've removed the rest (and added Xs) as I don't want some of the info publicly available.
Code: Select all
Array ( [HTTP_HOST] => XXXXX [HTTP_USER_AGENT] => Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Why not simply use get_browser() or variants thereof?
-
SteveMellor
- Forum Commoner
- Posts: 25
- Joined: Mon Jun 26, 2006 7:43 am
Actually I was using that, and it wasn't working. It was returning nothing when I tried to call it. It appears to be working now though.You need to use $_SERVER['HTTP_USER_AGENT'] if register_globals is off. In fact, I'll go further than that, you need to use $_SERVER['HTTP_USER_AGENT'] even if register_globals is on. Because register_globals is stupid and should be switched off.
As far as I am aware, get_browser uses the HTTP_USER_AGENT header as well, which I was unable to access.Why not simply use get_browser() or variants thereof?
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
I wrote a class (currently in Coding Critique) that will do what you need as well. get_browser() is a nice little function however.