Detecting Browsers with registered globals set to off

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
SteveMellor
Forum Commoner
Posts: 25
Joined: Mon Jun 26, 2006 7:43 am

Detecting Browsers with registered globals set to off

Post by SteveMellor »

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.
User avatar
stereofrog
Forum Contributor
Posts: 386
Joined: Mon Dec 04, 2006 6:10 am

Post by stereofrog »

What does this say?

Code: Select all

print_r($_SERVER);
SteveMellor
Forum Commoner
Posts: 25
Joined: Mon Jun 26, 2006 7:43 am

Post by SteveMellor »

Interestingly is says the following, which wasn't working before.

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
I've removed the rest (and added Xs) as I don't want some of the info publicly available.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Why not simply use get_browser() or variants thereof?
SteveMellor
Forum Commoner
Posts: 25
Joined: Mon Jun 26, 2006 7:43 am

Post by SteveMellor »

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.
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.
Why not simply use get_browser() or variants thereof?
As far as I am aware, get_browser uses the HTTP_USER_AGENT header as well, which I was unable to access.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

I wrote a class (currently in Coding Critique) that will do what you need as well. get_browser() is a nice little function however.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

SteveMellor wrote:
Why not simply use get_browser() or variants thereof?
As far as I am aware, get_browser uses the HTTP_USER_AGENT header as well, which I was unable to access.
It does, but it knows how to access it ;)
Post Reply