Get the IP address used by the user, the browser type, and the operating system
Reference Manual "HTTP_USER_AGENT" "Remote_Addr" "Remote_Port"
These three variables ~~~
Predefined variable server variable: $ _ server Note: Use in PHP 4.1.0 and later. Previous versions, use $ http_server_vars.
$ _Server is an array containing a hEADERS, Paths and Script Locations. The entity of the array is created by the web server. You cannot guarantee that all servers can generate all information; the server may ignore some information or have some new information not listed below. This means that a large number of variables are described in the CGI 1.1 Specification, so you should carefully study it.
This is a "superglobal" or can be described as an automatic global variable. This only means that it is valid in all scripts. You don't need to use Global $ _SERVER in a function or method; access it, just like $ http_server_vars.
$ Http_server_vars contains the same information, but is not an automatic global variable. (Note: $ http_server_vars and $ _server are different variables, and PHP handles them differently.)
If the register_globals directive is set, these variables are available in all scripts; that is, the $ _server and $ http_server_vars array are separated. For related information, see the relevant chapters of security using Register Global. These individual global variables are not automatic global variables.
You may find that some $ _server elements listed below are not available. Note that if PHP is run in a command line, the elements listed below are almost unable to be effective (or there is no practical meaning).
"PHP_SELF" is currently executing the file name of the script, related to Document Root. For example, using $ _SERVER ['php_self'] in the script of the URL address http://example.com/test.php/foo.bar will get /Test.php/foo.bar.
If PHP is running in a command line, the variable is invalid.
"Argv" passes the parameters of the script. When the script runs in the command line mode, the Argv variable passes the command line parameters of the program C language style. When the GET method is called, the variable contains the requested data.
"Argc" contains the number of command line parameters passed to the program (if running in command line mode).
The version of the CGI specification used by the "GATEWAY_INTERFACE" server. For example, "CGI / 1.1".
'Server_name' The name of the server host where the script is running the script. If the script is running on a virtual host, the name is determined by the value set by the virtual host.
The string of the 'Server_Software' server identifier is given in the header when the request is requested.
The "Server_Protocol" request page, the name and version of the communication protocol when the page is requested. For example, "http / 1.0".
"Request_Method" request method when accessing the page. For example: "Get", "Head", "POST", "PUT".
Query_String "string of query (query).
"Document_Root" The document root directory where the script is currently running. Define in the server profile.
"Http_accept" currently requested ACCEPT: Head content.
"Http_accept_charset" Currently requested Accept-Charset: The content of the header. For example: "ISO-8859-1, *, UTF-8". "Http_accept_encoding" Currently requested Accept-Encoding: Head content. For example: "gzip".
"Http_accept_language" Currently requested Accept-Language: Head content. For example: "en".
"Http_connection" currently requested Connection: Head content. For example: "Keep-alive".
"Http_host" Currently requested Host: The head of the header.
"Http_referer" is linked to the URL address of the previous page of the current page. Not all user agents (browser) will set this variable, and some can also modify http_referer. Therefore, this variable is not always true.
"Http_user_agent" Currently requested USER_AGENT: The content of the header. This string indicates the information of the user agent accessing the page. A typical example is: mozilla / 4.5 [en] (x11; u; linux 2.2.9 i586). You can also get this information using GET_BROWSER ().
"Remote_ADDR" is browsing the IP address of the current page user.
"Remote_Port" user is connected to the port used.
"Script_filename" currently executes the absolute path name of the script.
"Server_admin" This value indicates the Server_admin parameter in the Apache server configuration file. If the script is running on a virtual host, the value is the value of the virtual host.
The port used by the "Server_Port" server. The default is "80". If you use an SSL secure connection, this value is the HTTP port you set.
"Server_SIGNature" contains a string of the server version and the virtual hostname.
"Path_Translated" The basic path of the file system (not the document root directory) where the current script is located. This is the result after the server is virtual to the real path.
"Script_name" contains the path to the current script. This is very useful when you need to point to yourself.
"Request_uri" access the URI required for this page. For example, "/ INDEX.html".
"PHP_AUTH_USER" When PHP is running in the Apache module, and the HTTP authentication function is being used, this variable is the username input by the user.
"PHP_AUTH_PW" When PHP runs in the APACHE module, and the HTTP authentication function is being used, this variable is the password entered by the user.
"PHP_AUTH_TYPE" When PHP is running in the Apache module, and the HTTP authentication function is being used, this variable is the type of authentication.
Code Example 1, // Browser and Operating System Test $ Browser = $ _SERVER ['http_user_agent']; $ _ TEMP = EXPLODE (";", $ browser); // User Operating System $ _USER_OS = preg_replace ("//) . * / ", '', TRIM ($ _ TEMP [2]))); // User IP address $ _USER_IP = $ _SERVER ['Remote_addr']; IF (StrPos (STRTOLOWER)," MSIE ")) { // IE browser} IF (STRPOS (STRTOLOWER), "Opera")) {// Opera Browser} IF (STRPOS (STRPOS ($ Browser), "Gecko")) {// Mozilla Browser} IF (STRTOLOWER ($ Browser), "Netscape")) {// Netscape Browser} 2, $ IP = $ _SERVER ["Remote_Addr"];
// --------------------------------------- Function Osinfo () {OS = ""; $ Agent = $ _server ["http_user_agent"]; if (EREGI ('WIN', $ Agent) && Strpos ($ Agent, '95')) {$ OS = "Windows 95";} elseif (EREGI ('WIN 9X', $ Agent && Strpos ($ Agent, '4.90')) {$ OS = "Windows Me";} Elseif (EREGI ('Win', $ Agent) && EREG ('98 ', $ Agent )) {$ os = "windows 98";} elseif (EREGI ('WIN', $ Agent) && EREGI ('NT 5', $ Agent) {$ OS = "Windows 2000";} elseif (EREGI (' Win ', $ agent) && EREGI (' NT ', $ Agent) {$ OS = "Windows NT";} elseif (EREGI (' Win ', $ Agent) && EREG (' XP ', $ Agent) { $ os = "windows XP";} elseif (EREGI ('WIN', $ Agent) && EREG ('32 ', $ Agent) {$ OS = "Windows 32";} elseif (EREGI (' Linux ", $ Agent)) {$ OS = "Linux";} elseif (EREGI ('UNIX', $ Agent) {$ OS = "Unix";} elseif (EREGI ('Sun', $ Agent) && EREGI ('OS' , $ Agent)) {$ OS = "sunos";} elseif (EREGI (EREGI ('IBM', $ Agent) && EREGI ('OS', $ Agent) {$ OS = "IBM OS / 2";} elseif EREGI ('Mac', $ Agent) && EREGI ('PC', $ Agent) {$ OS = "Macintosh";} elseif (EREGI (EREGI ('PowerPC', $ Agent) {$ OS = "PowerPC"; Elseif (EREGI ('AIX', $ Agent) {$ OS = "AIX";} elseif (EREGi ('HP Ux ', $ agent) {$ os = "hpux";} elseif (EREGI (' NetBSD ', $ Agent) {$ OS = "NetBSD";} elseif (EREGI (' BSD ', $ Agent) { $ OS = "BSD";} elseif (EREG ('OSF1', $ Agent) {$ OS = "OSF1";} elseif (EREG ('Irix', $ Agent) {$ OS =
"Irix";} elseif
// ------------------------------------- Function Browseinfo () {$ Browser = ""; $ browserver = "; $ browsers = array (" Lynx "," Mosaic "," AOL "," Opera "," Java "," MacWeb "," WebExplorer "," OmniWeb "); $ Agent = $ _SERVER ["http_user_agent"]; for ($ I = 0; $ I <<($ i ) {IF (STRPOS ($ Agent, $ Browsers [$ I]) {$ Browser = $ Browsers [$ I ]; $ browserver = "";}}}} & (EREG ("Mozilla", $ Agent &&! EREG ("Msie", $ Agent) {$ TEMP = EXPLODE ("(", $ Agent); $ part = $ TEMP [0]; $ TEMP = EXPLODE ("/", $ part); $ browserver = $ TEMP [1]; $ TEMP = EXPLODE ("", $ browserver); $ browserver = $ temp [0]; $ Browserver = preg_replace ("/ ([/ d /.] )/","/ 1", $ browserver); $ browserver = "$ browserver"; $ browser = "netscape navigator";} if (EREG) Mozilla ", $ agent) && EREG (" Opera ", $ Agent) {$ TEMP = EXPLODE (" (", $ agent); $ part = $ temp [1]; $ temp = evLode (") ", $ Part); $ browserver = $ TEMP [1]; $ TEMP = EXPLODE ("", $ browserver); $ browserver = $ temp [2]; $ browserver = preg_replace ("/ ([/ d /.] )/ "," // 1 ", $ browserver; $ browserver =" $ browser Ver "; $ browser =" Opera ";} IF (EREG (" Mozilla ", $ Agent && EREG (" Msie ", $ Agent) {$ TEMP = EXPLODE (" (", $ AGENT); $ part = $ TEMP [1]; $ TEMP = EXPLODE (";", $ part); $ part = $ TEMP [1]; $ TEMP = EXPLODE ("", $ part); $ browserver = $ temp [2]; $ Browserver = preg_replace ("/ ([/ d /.] )/","// 1"