You are here:  » Mobile Detect and Redirect to Mobile Version


Mobile Detect and Redirect to Mobile Version

Submitted by chrisst1 on Thu, 2014-05-22 15:57 in

Hi David

I'm in the middle of creating a seperate mobile version of our PT site on a sub domain as making the main site responsive will take years. I've been searching the internet for a php script to detect mobile and tablets and redirect but I'm not really sure what would be the best way to go about this.

Could you make any suggestions or offer advice please.

Chris

Submitted by support on Thu, 2014-05-22 16:47

Hi Chris,

Most of the detection solutions seem to be either a substring comparison against the user-agent, which could be done in PHP, within your page header and redirect accordingly using a Location: header, or JavaScript solutions looking at various device capabilities, from which you could redirect with a meta refresh tag.

As a test, if you create a file width.html containing just:

<html>
<body>
<script type='text/JavaScript'>
document.write("Screen width is "+screen.width+" pixels");
</script>
</body>
</html>

Browse to that on a couple of desktop / mobile devices, and if you're happy that an arbitrary boundary in pixels could be chosen, and if viewing www. version and screen.width is less than the boundary then redirect to mobile. (or whatever subdomain you're using) that should be straight forward to incorporate into your header...

Cheers,
David.
--
PriceTapestry.com