|
PHP sets up a $_SERVER array which contains information such
as headers, paths, and script locations. These can be accessed
by $_SERVER['keyname'].
Functions.
The following shows how PHP can be used to get some basic
details on a session.
Getting user data
|
|
<?php
print("Browser: $HTTP_USER_AGENT <br />\n");
print("IP: $REMOTE_ADDR <br />\n");
print("Address: " . gethostbyaddr($REMOTE_ADDR));
?>
|
Executed code
|
|
Browser:
IP:
Warning: gethostbyaddr() [function.gethostbyaddr]: Address is not a valid IPv4 or IPv6 address in E:\kunden\homepages\29\d390184582\www\php_userdetails.php on line 113
Address:
|
The gethostbyaddr(IPaddress) does a reverse lookup on the
IP address (IPaddress), so that the domain name of the host
can be displayed. The following gives a more complete coverage
of the environ-ment variables:
Session data
|
|
<?php
print "<BR>CGI: $GATEWAY_INTERFACE";
print "<BR>Server:$SERVER_NAME";
print "<BR>Software:$SERVER_SOFTWARE";
print "<BR>Protocol:$SERVER_PROTOCOL";
print "<BR>Request:$REQUEST_METHOD";
print "<BR>Query:$QUERY_STRING";
print "<BR>Doc:$DOCUMENT_ROOT";
print "<BR>Remote IP:$REMOTE_ADDR";
print "<BR>Remote port:$REMOTE_PORT";
print "<BR>Sever port:$SERVER_PORT";
print "<BR>Remote agent:$HTTP_USER_AGENT";
print "<BR>URI:$REQUEST_URI";
?>
|
Executed code
|
|
CGI: Server: Software: Protocol: Request: Query: Doc: Remote IP: Remote port: Sever port: Remote agent: URI:
|
This could be implemented as follows:
HTTP parameters
|
|
<?php
print "<BR>HTTP Accept: $HTTP_ACCEPT";
print "<BR>HTTP Charset:$HTTP_ACCEPT_CHARSET";
print "<BR>HTTP Encoding:$HTTP_ACCEPT_ENCODING";
print "<BR>HTTP Language:$HTTP_ACCEPT_LANGUAGE";
print "<BR>HTTP Connection:$HTTP_CONNECTION";
print "<BR>HTTP Host:$HTTP_HOST";
print "<BR>HTTP Referer:$HTTP_REFERER";
?>
|
Executed code
|
|
HTTP Accept: HTTP Charset: HTTP Encoding: HTTP Language: HTTP Connection: HTTP Host: HTTP Referer:
|
There are also several core constants, such as __FILE__ (which
shows the filename of the script being processed), PHP_VERSION
(the PHP version) and PHP_OS (the PHP operating system), as
given next.
Environment
|
|
<?php
print
"<BR>File is " . __FILE__;
print "<BR>PHP Version is " . PHP_VERSION;
print "<BR>Operating System is " . PHP_OS;
?>
|
Executed code
|
|
File is E:\kunden\homepages\29\d390184582\www\php_userdetails.php PHP Version is 5.3.5 Operating System is WINNT
|
|