Determine client OS in PHP

前端 未结 2 1620
生来不讨喜
生来不讨喜 2021-01-14 16:30

I have two pages redirection in my index.php. The pages are example_system_os.php and example_mobile_os.php.

How to determine the user\'s o

相关标签:
2条回答
  • 2021-01-14 16:39

    The get_browser function can be used to extract a couple of information the User-Agent HTTP header sent by the browser.

    Amongst those informations, it seems there is some data about the operating system the browser's running on -- i.e. about the client OS.


    Quoting the example given on the manual page of get_browser :

    Array
    (
        [browser_name_regex] => ^mozilla/5\.0 (windows; .; windows nt 5\.1; .*rv:.*) gecko/.* firefox/0\.9.*$
        [browser_name_pattern] => Mozilla/5.0 (Windows; ?; Windows NT 5.1; *rv:*) Gecko/* Firefox/0.9*
        [parent] => Firefox 0.9
        [platform] => WinXP
        [browser] => Firefox
        [version] => 0.9
    


    But note that the User-Agent HTTP header is sent by the client, which means :

    • It can be disabled
    • It can be faked (i.e. you can get any kind of garbage in it ^^ )
    0 讨论(0)
  • 2021-01-14 16:46

    You could parse the $_SERVER['HTTP_USER_AGENT'] string for the various platform details, but I wouldn't be confident that this was a deterministic approach, since it can easily be faked.

    0 讨论(0)
提交回复
热议问题