Gardacus Posted November 15, 2012 Share Posted November 15, 2012 Hi all I am not sure if this topic exists or where to place it, so please forgive me if I posted this on the wrong site. I am looking for a smart (PHP preferred) solution to redirect mobile devices to a mobile version of a website. At this moment this is my javascript solution, but it is not fool-proof: <script type="text/javascript"> if ((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1) || (navigator.userAgent.indexOf('iPad') != -1) || (navigator.userAgent.indexOf('Blackberry') != -1) || (navigator.userAgent.indexOf('Opera Mini') != -1) || (navigator.userAgent.indexOf('WebKit') != -1)) { document.location ="mobile/index.html"; } </script> It works on the devices mentioned, but Safari on an iMac also is seen as a mobile device, and therefore redirected to the mobile site. Is there any smart solution for this that I can build in PHP? Thanks all! Mike Link to comment Share on other sites More sharing options...
Larry Posted November 16, 2012 Share Posted November 16, 2012 You really don't want to code this yourself. Use this instead: http://detectmobilebrowsers.com/ 1 Link to comment Share on other sites More sharing options...
Recommended Posts