Search the Community
Showing results for tags 'mobile device identification'.
-
I have a client that would like me to identify if the user has a mobile device, and if so redirect them to a mobile webpage; if not, then redirect them to a non-mobile webpage. I have used the code listed below with success for another client, but for my latest client it is not working. Here is the code: <?php $mobileURL='http://my.url/mobile/index.php'; $url='http://my.url/index.php'; function isMobile() { return preg_match("/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", $_SERVER["HTTP_USER_AGENT"]); } // If the user is on a mobile device, redirect them if(isMobile()){ // echo '<a href="'.$mobileURL.'">'.$mobileURL.'</a>'; header('Location: $mobileURL'); /* Make sure that code below does not get executed when we redirect. */ exit; }else{ // echo '<a href="'.$url.'">'.$url.'</a>'; header('Location: $url'); } ?> The code works fine when I use the echo statements in the if/then statement, but not if I use the header() coding. The following is what I get: On Laptop: (the emoticon below is supposed to read the number 8 with a closed paranthesis) On iPhone: (the emoticon below is supposed to read the number 8 with a closed paranthesis) Please let me know what I am doing wrong and how to fix it.
- 10 replies
-
- mobile device identification
- header
-
(and 1 more)
Tagged with: