Home  >  Article  >  Backend Development  >  How to use PHP to judge the mobile phone and jump to it

How to use PHP to judge the mobile phone and jump to it

藏色散人
藏色散人Original
2020-10-10 10:12:523102browse

The implementation method of php judging the mobile phone and jumping: first create a PHP sample file; then encapsulate the code for judging the jump into a commonly used function "ismobile"; finally use the ismobile function directly to judge the jump Just turn.

How to use PHP to judge the mobile phone and jump to it

Recommendation: "PHP Video Tutorial"

PHP webpage determines the mobile phone version and automatically jumps to the mobile phone page

//新增 如果是手机访问 则跳转到手机端页面
        if(strpos($agent,"comFront") || strpos($agent,"iPhone") || strpos($agent,"MIDP-2.0") || strpos($agent,"Opera Mini") || strpos($agent,"UCWEB") || strpos($agent,"Android") || strpos($agent,"Windows CE") || strpos($agent,"SymbianOS"))
        header("Location:http://hd2017.cn/index.php?m=mobile&a=index");

We can encapsulate it into a commonly used function!

// $murl 为手机端的页面地址
    function ismobile($murl=""){
        //新增 如果是手机访问 则跳转到手机端页面 
        if(strpos($agent,"comFront") || strpos($agent,"iPhone") || strpos($agent,"MIDP-2.0") || strpos($agent,"Opera Mini") || strpos($agent,"UCWEB") || strpos($agent,"Android") || strpos($agent,"Windows CE") || strpos($agent,"SymbianOS"))
        header("Location:{$murl}");
    }

This will be much more convenient when we use it!

The above is the detailed content of How to use PHP to judge the mobile phone and jump to it. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn