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
bruceg
Forum Contributor
Posts: 174 Joined: Wed Mar 16, 2005 11:07 am
Location: Morrisville, NC
Contact:
Post
by bruceg » Fri Jul 01, 2005 5:16 pm
Hello,
I am using PHP code to try and indentify browser and platform, but it doesn't seem to be working.
No matter what browser I use, I just get a msg stating "unidentified browser". I am sure there is a problem with the code. Here it is:
Code: Select all
<?php $viewer = getenv ( "HTTP_USER_Agent:" );
$Browser ="an unidentified browser";
if (preg_match( "/MSIE/i", $viewer ) )
{$browser="Internet Explorer"; }
else if (preg_match( "/Netscape/i", $viewer ) )
{$browser="Netscape"; }
else if (preg_match( "/Opera/i", $viewer ) )
{$browser="Opera"; }
else if (preg_match( "/Mozilla/i", $viewer ) )
{$browser="Mozilla"; }
else if (preg_match( "/Firefox/i", $viewer ) )
{$browser="Firefox"; }
else if (preg_match( "/Mozilla/i", $viewer ) )
{$browser="Mozilla"; }
$platform = "an unidentified operating system" ;
if ( preg_match( "/Windows/i", $viewer ) )
{ $platform="windows"; }
else if(preg_match( "/Macintosh/i" , $viewer ) )
{ $platform ="Macintosh"; }
echo ( "<p>You're using $browser on $platform</p>" );
?>
the page can be found at
http://www.inspired-evolution.com/Brows ... cation.php
Thanks in advance for any assistance.
Burrito
Spockulator
Posts: 4715 Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah
Post
by Burrito » Fri Jul 01, 2005 5:18 pm
try:
Code: Select all
$viewer = $_SERVER['HTTP_USER_AGENT'];
I'm sure the evn var would work too, but AGENT needs to be caps.
bruceg
Forum Contributor
Posts: 174 Joined: Wed Mar 16, 2005 11:07 am
Location: Morrisville, NC
Contact:
Post
by bruceg » Fri Jul 01, 2005 5:35 pm
thanks,
but I changed AGENT to caps and it still doesn't want to work
Burrito
Spockulator
Posts: 4715 Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah
Post
by Burrito » Fri Jul 01, 2005 6:01 pm
did you try using the $_SERVER[] array?
bruceg
Forum Contributor
Posts: 174 Joined: Wed Mar 16, 2005 11:07 am
Location: Morrisville, NC
Contact:
Post
by bruceg » Fri Jul 01, 2005 6:29 pm
no,
where would I put the $SERVER array in the above code?
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098 Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia
Post
by Chris Corbyn » Fri Jul 01, 2005 8:34 pm
bruceg wrote: no,
where would I put the $SERVER array in the above code?
Code: Select all
$viewer = $_SERVER['HTTP_USER_AGENT'];
You may find it useful to print_r($_SERVER) and inspect it too
R0d Longfella
Forum Newbie
Posts: 20 Joined: Fri Apr 08, 2005 7:17 am
Post
by R0d Longfella » Sat Jul 02, 2005 8:33 am
Not all browser identify themselves. I don't know if Mozilla identifies itself by default. So first inspect $_SERVER with print_r (); You might get a clue.