Jump to content
Larry Ullman's Book Forums
Sign in to follow this  
Gardacus

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

}

</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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...