Get operating system info

后端 未结 7 1191
借酒劲吻你
借酒劲吻你 2020-11-22 14:48

I recently started wondering about sites like http://thismachine.info/ that get the user\'s operating system info. I have not been able to find out how to do that with PHP,

7条回答
  •  感动是毒
    2020-11-22 15:39

    When you go to a website, your browser sends a request to the web server including a lot of information. This information might look something like this:

    GET /questions/18070154/get-operating-system-info-with-php HTTP/1.1  
    Host: stackoverflow.com  
    User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 
                (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36 
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8  
    Accept-Language: en-us,en;q=0.5  
    Accept-Encoding: gzip,deflate,sdch  
    Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7  
    Keep-Alive: 300  
    Connection: keep-alive  
    Cookie:  
    Pragma: no-cache  
    Cache-Control: no-cache
    

    These information are all used by the web server to determine how to handle the request; the preferred language and whether compression is allowed.

    In PHP, all this information is stored in the $_SERVER array. To see what you're sending to a web server, create a new PHP file and print out everything from the array.

    This will give you a nice representation of everything that's being sent to the server, from where you can extract the desired information, e.g. $_SERVER['HTTP_USER_AGENT'] to get the operating system and browser.

提交回复
热议问题