Simplest way to detect a mobile device in PHP

后端 未结 15 2551
别跟我提以往
别跟我提以往 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:24

    In case you care about screen size you can store screen width and Height as cookie values if they do not exists yet and then make self page redirection.

    Now you have cookies on client and server side and can use it to determine mobile phones, tablets and other devices

    Here a quick example how you can do it with JavaScript. Warning! [this code contain pseudo code].

    if (!getcookie("screen_size")) {
        var screen_width = screen.width;
        var screen_height = screen.height;
        setcookie("screen_size", screen_width+", " +screen_height);
        go2(geturl());
    }
    

提交回复
热议问题