Browse - programming tips - browser detection in perl cgiDate: 2008apr11 Level: Beginner Language: perl Q. On a server-side CGI script how do I detect which browser the user is running? A. Please note that its best to use feature detection rather than browser detection. Maybe the next version of IE will have that feature you assume it doesn't have. Here are some simple perl code that sees what browser the user is running: sub isFirefox() { return $ENV{HTTP_USER_AGENT} =~ m/Firefox/; } sub isIE() { return $ENV{HTTP_USER_AGENT} =~ m/MSIE/; } # Use like this... sub main() { print "Content-Type: text/plain\n\n"; if (isFirefox()) { print "You seem to be using Firefox\n"; } elsif (isIE()) { print "You seem to be using Microsoft Internet Explorer\n"; } else { print "You're not using Firefox or MSIE\n"; } } main();
CommentFrom: hey Date: 2009nov25 19:34 Subject: Thanks Thanks for the info dave! Add a commentSign in to add a comment |