Just get the environment variable HTTP_USER_AGENT and it will give you the user agent string sent in http header User-Agent:. You might want to use this page http://www.siteware.ch/webresources/useragents/db.html to get a comprehensive list of user agents