Simplest way to detect a mobile device in PHP

后端 未结 15 2334
别跟我提以往
别跟我提以往 2020-11-22 05:12

What is the simplest way to tell if a user is using a mobile device to browse my site using PHP?

I have come across many classes that you can use but I was hoping fo

15条回答
  •  渐次进展
    2020-11-22 05:33

    Maybe combining some javascript and PHP could achieve the trick

    ';
    $string .= 'if ( /Opera|OPR\/|Puffin|Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) { ';
    $string .= '        alert("CELL")';
    $string .= '    } else {';
    $string .= '        alert("NON CELL")';
    $string .= '    }       ';  
    $string .= ''; 
    echo $string;
    ?>
    

    I used that with plain javascript also instead

提交回复
热议问题