Jump to content
Larry Ullman's Book Forums

User Agent Definitions In Php

Recommended Posts

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";




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!



Link to comment
Share on other sites


  • Create New...