php检测客户端浏览器类型代码
<html> <body> <?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( "/Mozilla/i", "$viewer" ) ) { $browser = "Mozilla"; } $platform = "An unidentified OS!"; if( preg_match( "/Windows/i", "$viewer" ) ) { $platform = "Windows!"; } else if ( preg_match( "/Linux/i", "$viewer" ) ) { $platform = "Linux!"; } echo("You are using $browser on $platform"); ?> </body> </html>
输出结果如下
You are using Mozilla! on Windows!