I see that mobile versions of websites often begin with an “m.” (e.g. http://m.accuweather.com). I’d like to redirect my mobile users to http://m.mysite.com
so that I can display a different page.
- What’s the standard practice way to feed mobile devices the mobile version of a site? Does one detect the type of device on the server-side (if that’s even possible) or on the client-side?
- How does one detect whether a mobile device is accessing a site on both the server-side (using PHP) and client-side (using jQuery)?
- Is it possible to detect if it’s a mobile device on an Apache level? Or would I constantly have to use PHP scripts to check if it’s a mobile device and redirect to the appropriate version of the page?
Advertisement
Answer
The easiest way is checking the user agent, available via $_SERVER['HTTP_USER_AGENT']
. While clients can send any string, people usually do not pretend to be a mobile browser if they aren’t (and if they do so – not your problem).