Determining Browser Type

You want to know the browser type.

Check $_SERVER['HTTP_USER_AGENT'].

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="EN" lang="EN">
<head>
<title>PHP</title>
<meta Name="Author" Content="Hann So">
</head>
<body>
<p>
<?php
function display_form() {
echo <<<HTML
Determining Browser Type
<form action = "$_SERVER[SCRIPT_NAME]" method="post">
<input type="submit" name="submit" value="Go">
</form>
HTML;
}

function perform_form() {
	echo $_SERVER['HTTP_USER_AGENT'], "<br /><br />";
	if (strpos($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
		echo "You are using IE.<br />";
	} elseif (strpos($_SERVER['HTTP_USER_AGENT'], "Firefox")) {
		echo "You are using Firefox.<br />";
	} else {
		echo "You are using other browsers.<br />";
	}
}

if (isset($_POST['submit'])) {
	perform_form();
}
else {
	display_form();
}
?>
</p>
</body>
</html>

View the effect


Forms | Introduction | Creating a Form | Superglobals | Processing Form Input | Required Fields | Numbers | Drop-Down Menus | Radio Buttons | Checkboxes | Periods in Their Names | Preventing Cross-Site Scripting | Stripping out Slashes | Redirecting the User | Server Information | Determining Browser Type | Sticky Forms
© 2008: Hann So
email: hso@voyager.deanza.edu