Page 1 of 1

Browser Identification Code not working

Posted: Fri Jul 01, 2005 5:16 pm
by bruceg
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.

Posted: Fri Jul 01, 2005 5:18 pm
by Burrito
try:

Code: Select all

$viewer = $_SERVER['HTTP_USER_AGENT'];
I'm sure the evn var would work too, but AGENT needs to be caps.

Posted: Fri Jul 01, 2005 5:35 pm
by bruceg
thanks,

but I changed AGENT to caps and it still doesn't want to work :-(

Posted: Fri Jul 01, 2005 6:01 pm
by Burrito
did you try using the $_SERVER[] array?

Posted: Fri Jul 01, 2005 6:29 pm
by bruceg
no,

where would I put the $SERVER array in the above code?

Posted: Fri Jul 01, 2005 8:34 pm
by Chris Corbyn
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 ;)

Posted: Sat Jul 02, 2005 8:33 am
by R0d Longfella
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.

Posted: Sat Jul 02, 2005 8:36 am
by Roja
Why not just dig through the code in the excellent http://phpsniff.sourceforge.net/ ?