Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect in perl if the client is using a mobile browser?

I'm using a CGI script to generate a dynamic webpage. I want the page to load elements differently depending on whether or not the user is using a phone (such as a blackberry) to access the website or a normal browser. Is there an environment detail I can grab to make this decision? What would be the best method of doing this (even if its using javascript and not CGI.)

like image 990
WillHaack Avatar asked Aug 18 '11 13:08

WillHaack


People also ask

What is the best way to detect a mobile device?

In summary, we recommend looking for the string “Mobi” anywhere in the User Agent to detect a mobile device. Like this: if (/Mobi/. test(navigator.


1 Answers

Use the Perl variable $ENV{'HTTP_USER_AGENT'} and the HTTP::BrowserDetect module.

Once you have the determined what browser the client is using (e.g. is it a mobile browser) - then you can make the decision on what to send back to the client (mobile version or desktop version etc)

like image 151
Bruce Avatar answered Oct 12 '22 06:10

Bruce