$agent = $_SERVER['HTTP_USER_AGENT']
It is always best to use isset() function to grab the value from the variable, otherwise you'll get error if the value is not set. In that case it will be
$agent = $_SERVER['HTTP_USER_AGENT'];
Now lets analyze about the user's browser. From the user agent string, you can easily differentiate the browser name of user. For example if you want to provide different types of PHP code for Mozilla users. To identify the Mozilla user, code will be
print "Firefox user.";
// process here for firefox browser
For other browsers, you just need to change the regular expression. Below are the two regular expression for Opera and Internet Explorer.
Here /i means the string is case insensitive.
For more PHP related topics, here is my other posts http://icfun.blogspot.com/search/label/php