PHP Super Variables

1. $_SERVER[‘PHP_SELF’];
Example:  /tutorials/$_server_requested/$_SERVER.php (Return Path after localhost or domain url)
2. $_SERVER[‘DOCUMENT_ROOT’];Example: C:/xampp/htdocs
3. $_SERVER[‘HTTP_HOST’];
Example: localhost (It Will return a host name)

$_SERVER[‘REMOTE_ADDR’]; // Returns the IP address from which the user is viewing the current page.For Ex.: 127.0.0.1(If it is on Local Server)
$_SERVER[‘REMOTE_PORT’]; // States name of the host server. The port being used on the user’s machine to communicate with the web server. For Ex.: 4546 (My Machine)

$_SERVER[‘GATEWAY_INTERFACE’]; // CGI/1.1
/*$_SERVER[‘GATEWAY_INTERFACE’] variable returns the version of the Common Gateway Interface (CGI) specification the server is using. For example CGI/1.1 is a valid GATEWAY_INTERFACE.*/

$_SERVER[‘QUERY_STRING’];
// It Will Return this—> id=1 if your url is like given below in Ex.
// returns query string For Ex: http://localhost/tutorialsrnd/$_server_requested/$_SERVER.php?id=1

$_SERVER[‘HTTP_ACCEPT’]; // text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
/*If exists, contents of the Accept: header from the current request is fetched by $_SERVER[‘HTTP_ACCEPT’].*/

$_SERVER[‘HTTP_ACCEPT_CHARSET’]; // ISO-8859-1,utf-8;q=0.7,*;q=0.7
/*If exists, contents of the Accept-Charset: header from the current request is fetched by $_SERVER[‘HTTP_ACCEPT_CHARSET’].*/

$_SERVER[‘HTTP_ACCEPT_ENCODING’]; // gzip, deflate
/*Contents of the Accept-Encoding: header from the current request, if there is one. Example: ‘gzip’. */

$_SERVER[‘HTTP_ACCEPT_LANGUAGE’]; // en-us,en;q=0.5
/*The basic command we will use to know the languages selected in the browser.*/

$_SERVER[‘HTTP_CONNECTION’];
/*Contents of the Connection: header from the current request, if there is one. Example: ‘Keep-Alive’. */

$_SERVER[‘HTTP_REFERER’];
/*$_SERVER[‘HTTP_REFERER’] can be used to fetch the complete URL of the current page.
Since some but not all user agents (for example browsers) don’t support it, usage of this is not much reliable.*/

$_SERVER[‘HTTP_USER_AGENT’]; // Mozilla/5.0 (Windows NT 5.1; rv:11.0) Gecko/20100101 Firefox/11.0
/*If exists, contents of the User-Agent: header from the current request is fetched by $_SERVER[‘HTTP_USER_AGENT’].*/

$_SERVER[‘PATH_TRANSLATED’];
/*$_SERVER[‘PATH_TRANSLATED’] fetches the file system based path to the current script. This is accomplished after the server has done any virtual-to-real mapping.
It works only when PATH_INFO is defined.*/

Leave a Reply

Your email address will not be published. Required fields are marked *