0

I would like to know how to display a template for mobile users, and a template for desktop users on a j2.5 site? Is this possible without using a sub domain?

If not, then what is the most efficient way to detect a mobile user, and display an alternative .css file only (as opposed to a different template)?

theoth
  • 127
  • 3
  • 11
  • 1
    Duplicate - http://stackoverflow.com/questions/1005153/auto-detect-mobile-browser-via-user-agent – Bibhas Debnath Apr 25 '12 at 22:05
  • 2
    There are thousands upon thousands of pages out on the web that cover every aspect of this topic. As a word of caution, the methods for sniffing browsers are generally the subject of long debates over accuracy, reliability, scalability, etc – orourkek Apr 25 '12 at 22:18
  • Hi, yes I am aware of the many posts about mobile detection in general, however I am asking above then switching the template in joomla, and if this isn't possible without using a sub domain, then use an alternative .css file. – theoth Apr 25 '12 at 22:52

1 Answers1

1

You can detect the users browser (including mobile) via the browsers User Agent. In PHP this is available through

$_SERVER['HTTP_USER_AGENT']

which will display a string like

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.165 Safari/535.19

That's my current user agent using Chrome on a MacBook.

You can run a regex match against this string to match to known mobile browsers and redirect the to a mobile version of the site. Most websites use a m. or mobile. subdomain.

Brandon Cordell
  • 1,308
  • 1
  • 9
  • 24