0

it is such that I know only imagine that when you are log on mobile then you should be sent to mobil.navn.dk. it is only if you are on iphone or ipad or other mobiles. then dne do like that. and if you are on the browser it should not be possible to log on browser page that is navn.dk.

I've tried to do this:

<script type="text/javascript">
if (screen.width<800) {
    window.location="http://mobil.mebe.dk/";
}
</script>

and i have tried this here:

<?php
            function detect_mobile()
            {
                if(preg_match('/(alcatel|amoi|android|avantgo|blackberry|benq|cell|cricket|docomo|elaine|htc|iemobile|iphone|ipad|ipaq|ipod|j2me|java|midp|mini|mmp|mobi|motorola|nec-|nokia|palm|panasonic|philips|phone|playbook|sagem|sharp|sie-|silk|smartphone|sony|symbian|t-mobile|telus|up\.browser|up\.link|vodafone|wap|webos|wireless|xda|xoom|zte)/i', $_SERVER['HTTP_USER_AGENT']))
                    header('Location: http://mobil.navn.dk/');
                else
                    header('Location: http://www.navn.dk/');
            }
        ?>

JavaScript seems to me just seems too old-fashioned or is there any other way to do it?

Mr. Alien
  • 153,751
  • 34
  • 298
  • 278

1 Answers1

2

There's actually quite easy metod for detecting an device that you want do detect, and you can do it like this:

if(strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'mobile') || strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'android')) {
   echo "You are running a mobile webbrowser!";

You can add in "if" as many devices as you want so you can easilly adjust this in a way that you need.

Bojan Kopanja
  • 734
  • 5
  • 15