PHP/HTML/HTTP USER AGENT — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 10:37, 26 мая 2010
Содержание
Browser content
<html>
<head>
<title>Browser content</title>
</head>
<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( "/Opera/i", "$viewer"))
{ $browser = "Opera"; }
$platform = "an unidentified operating system";
if( preg_match( "/Windows/i", "$viewer"))
{ $platform = "Windows"; }
else if( preg_match( "/Linux/i", "$viewer"))
{ $platform = "Linux"; }
echo( "You"re using $browser on $platform" );
?>
</body>
</html>
Browser Detection
<?
echo $HTTP_USER_AGENT;
?>
Determining client operating system and browser
<?
function browser_info ($agent) {
if (ereg( "MSIE ([0�9].[0�9]{1,2})", $agent, $version)) :
$browse_type = "IE";
$browse_version = $version[1];
elseif (ereg( "Opera ([0�9].[0�9]{1,2})", $agent, $version)) :
$browse_type = "Opera";
$browse_version = $version[1];
elseif (ereg( "Mozilla/([0�9].[0�9]{1,2})", $agent, $version)) :
$browse_type = "Netscape";
$browse_version = $version[1];
else :
$browse_type = "Unknown";
$browse_version = "Unknown";
endif;
return array($browse_type, $browse_version);
}
function operatingsystem_info($agent) {
if ( strstr ($agent, "Win") ) :
$operatingsystem = "Windows";
elseif ( strstr($agent, "Linux") ) :
$operatingsystem = "Linux";
elseif ( strstr ($agent, "Unix") ) :
$operatingsystem = "Unix";
elseif ( strstr ($agent,"Mac") ) :
$operatingsystem = "Macintosh";
else :
$operatingsystem = "Unknown";
endif;
return $operatingsystem;
}
list ($browse_type, $browse_version) = browser_info ($HTTP_USER_AGENT);
$operating_sys = operatingsystem_info ($HTTP_USER_AGENT);
print "Browser Type: $browse_type <br>";
print "Browser Version: $browse_version <br>";
print "Operating System: $operating_sys <br>";
?>
Get Browser and Platform
<html>
<head>
<title>Get Browser & Platform</title>
</head>
<body>
<?php
$viewer = getenv( "HTTP_USER_AGENT" );
echo( "Browser details:<br>$viewer" );
?>
</body>
</html>
Reporting the User Agent and Referrer
<html>
<head>
<title>Reporting User Agent and Referrer</title>
</head>
<body>
<div>
<p>
Browser: <b><?php print $_SERVER["HTTP_USER_AGENT"] ?></b><br />
Referring page: <b><?php print $_SERVER["HTTP_REFERER"] ?></b>
</p>
</div>
</body>
</html>
Welcome Page with HTTP_USER_AGENT
<html>
<head>
<title>Welcome Page</title>
</head>
<body>
<center>
<?php
$browser = $_SERVER["HTTP_USER_AGENT"];
if( preg_match( "/Pixo/i", "$browser" ) )
{
$img = "<img src=\"small-tux.gif\" ";
$img.= "width=\"64\" height=\"75\" ";
$img.= " alt=\"tux\" >";
}
else
{
$img = "<img src=\"large-tux.gif\" ";
$img.= " width=\"320\" height=\"375\" ";
$img.= " alt=\"tux\" >";
}
echo( $img );
?>
</center>
</body>
</html>