Created
September 28, 2012 08:33
-
-
Save rifki/3798659 to your computer and use it in GitHub Desktop.
Environment Class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Copyright @author Muhamad Rifki <rifki@rifkilabs.net> | |
* Deskripsi : http://php.net/manual/en/reserved.variables.server.php | |
*/ | |
abstract class EnvironmentAbstract | |
{ | |
/** | |
* The address of the page (if any) which referred the user agent to the current page. | |
* This is set by the user agent. Not all user agents will set this, | |
* and some provide the ability to modify HTTP_REFERER as a feature. In short, | |
* it cannot really be trusted | |
* @var type | |
*/ | |
protected $http_referer = "http_referer"; | |
/** | |
* Contents of the Host: header from the current request, if there is one. | |
* @var type | |
*/ | |
protected $http_host = "http_host"; | |
/** | |
* Contents of the User-Agent: header from the current request, | |
* if there is one. This is a string denoting the user agent | |
* being which is accessing the page. | |
* A typical example is: Mozilla/4.5 [en] (X11; U; Linux 2.2.9 i586). | |
* Among other things, you can use this value with get_browser() | |
* to tailor your page's output to the capabilities of the user agent. | |
* @var type | |
*/ | |
protected $http_user_agent = "http_user_agent"; | |
/** | |
* Contents of the Accept: header from the current request, if there is one. | |
* @var type | |
*/ | |
protected $http_accept = "http_accept"; | |
/** | |
* Contents of the Accept-Language: header from the current request, | |
* if there is one. Example: 'en'. | |
* @var type | |
*/ | |
protected $http_accept_languange = "http_accept_languange"; | |
/** | |
* Contents of the Accept-Encoding: header from the current request, | |
* if there is one. Example: 'gzip'. | |
* @var type | |
*/ | |
protected $http_accept_encoding = "http_accept_encoding"; | |
/** | |
* Contents of the Accept-Charset: header from the current request, | |
* if there is one. Example: 'iso-8859-1,*,utf-8'. | |
* @var type | |
*/ | |
protected $http_accept_charset = "http_accept_charset"; | |
/** | |
* Contents of the Connection: header from the current request, | |
* if there is one. Example: 'Keep-Alive'. | |
* @var type | |
*/ | |
protected $http_connection = "http_connection"; | |
/** | |
* /usr/local/bin:/usr/bin:/bin | |
* @var type | |
*/ | |
protected $path = "path"; | |
/** | |
* String containing the server version and virtual host name | |
* which are added to server-generated pages, if enabled. | |
* @var type | |
*/ | |
protected $server_signature = "server_signature"; | |
/** | |
* Server identification string, given in the headers when responding to requests. | |
* @var type | |
*/ | |
protected $server_software = "server_software"; | |
/** | |
* The name of the server host under which the current script is executing. | |
* If the script is running on a virtual host, | |
* this will be the value defined for that virtual host. | |
* @var type | |
*/ | |
protected $server_name = "server_name"; | |
/** | |
* The IP address of the server under which the current script is executing. | |
* @var type | |
*/ | |
protected $server_addr = "server_addr"; | |
/** | |
* The port on the server machine being used by the web server for communication. | |
* For default setups, this will be '80'; using SSL, for instance, | |
* will change this to whatever your defined secure HTTP port is. | |
* @var type | |
*/ | |
protected $server_port = "server_port"; | |
/** | |
* The IP address from which the user is viewing the current page. | |
* @var type | |
*/ | |
protected $remote_addr = "remote_addr"; | |
/** | |
* The document root directory under which the current script is executing, | |
* as defined in the server's configuration file. | |
* @var type | |
*/ | |
protected $document_root = "document_root"; | |
/** | |
* The value given to the SERVER_ADMIN (for Apache) | |
* directive in the web server configuration file. | |
* If the script is running on a virtual host, | |
* this will be the value defined for that virtual host. | |
* @var type | |
*/ | |
protected $server_admin = "server_admin"; | |
/** | |
* The absolute pathname of the currently executing script. | |
* @var type | |
*/ | |
protected $script_filename = "script_filename"; | |
/** | |
* The port being used on the user's machine to communicate with the web server. | |
* @var type | |
*/ | |
protected $remote_port = "remote_port"; | |
/** | |
* What revision of the CGI specification the server is using; i.e. 'CGI/1.1'. | |
* @var type | |
*/ | |
protected $gateway_interface = "gateway_interface"; | |
/** | |
* Name and revision of the information protocol via which the page was requested; | |
* i.e. 'HTTP/1.0'; | |
* Note: | |
* PHP script is terminated after sending headers (it means after producing any | |
* output without output buffering) if the request method was HEAD. | |
* @var type | |
*/ | |
protected $server_protocol = "server_protocol"; | |
/** | |
* Which request method was used to access the page; i.e. 'GET', 'HEAD', 'POST', 'PUT'. | |
* @var type | |
*/ | |
protected $request_method = "request_method"; | |
/** | |
* The timestamp of the start of the request. Available since PHP 5.1.0. | |
* @var type | |
*/ | |
protected $request_time = "request_time"; | |
/** | |
* The timestamp of the start of the request, with microsecond precision. | |
* Available since PHP 5.4.0. | |
* @var type | |
*/ | |
//protected $request_time_float = "request_time_method"; | |
/** | |
* The query string, if any, via which the page was accessed. | |
* @var type | |
*/ | |
protected $query_string = "query_string"; | |
/** | |
* The URI which was given in order to access this page; for instance, '/index.html'. | |
* @var type | |
*/ | |
protected $request_uri = "request_uri"; | |
/** | |
* Contains the current script's path. This is useful for pages | |
* which need to point to themselves. | |
* The __FILE__ constant contains the full path and | |
* filename of the current (i.e. included) file. | |
* @var type | |
*/ | |
protected $script_name = "script_name"; | |
/** | |
* must implement on class | |
*/ | |
abstract protected function getValue(); | |
/** | |
* common access method | |
*/ | |
public function printOut() | |
{ | |
var_export($this->getValue()); | |
} | |
} | |
class ApacheEnvironment extends EnvironmentAbstract | |
{ | |
protected function getValue() | |
{ | |
return array( | |
$_SERVER['HTTP_REFERER'] => $this->http_referer, | |
$_SERVER['HTTP_HOST'] => $this->http_host, | |
$_SERVER['HTTP_USER_AGENT'] => $this->http_user_agent, | |
$_SERVER['HTTP_ACCEPT'] => $this->http_accept, | |
$_SERVER['HTTP_ACCEPT_LANGUAGE']=> $this->http_accept_languange, | |
$_SERVER['HTTP_ACCEPT_ENCODING']=> $this->http_accept_encoding, | |
$_SERVER['HTTP_ACCEPT_CHARSET'] => $this->http_accept_charset, | |
$_SERVER['HTTP_CONNECTION'] => $this->http_connection, | |
$_SERVER['PATH'] => $this->path, | |
$_SERVER['SERVER_SIGNATURE'] => $this->server_signature, | |
$_SERVER['SERVER_SOFTWARE'] => $this->server_software, | |
$_SERVER['SERVER_NAME'] => $this->server_name, | |
$_SERVER['SERVER_ADDR'] => $this->server_addr, | |
$_SERVER['REMOTE_ADDR'] => $this->remote_addr, | |
$_SERVER['DOCUMENT_ROOT'] => $this->document_root, | |
$_SERVER['SERVER_ADMIN'] => $this->server_admin, | |
$_SERVER['SCRIPT_FILENAME'] => $this->script_filename, | |
$_SERVER['REMOTE_PORT'] => $this->remote_port, | |
$_SERVER['GATEWAY_INTERFACE'] => $this->gateway_interface, | |
$_SERVER['SERVER_PROTOCOL'] => $this->server_protocol, | |
$_SERVER['REQUEST_METHOD'] => $this->request_method, | |
$_SERVER['REQUEST_TIME'] => $this->request_time, | |
$_SERVER['QUERY_STRING'] => $this->query_string, | |
$_SERVER['REQUEST_URI'] => $this->request_uri, | |
$_SERVER['SCRIPT_NAME'] => $this->script_name | |
); | |
} | |
} | |
$obj = new ApacheEnvironment(); | |
echo "<pre>"; | |
$obj->printOut() . "<br />"; | |
echo "</pre>"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment