Tuesday, 28 May 2013

Super Global Variable $_SERVER In PHP

$_SERVER

$_SERVER is an array containing information such as headers, paths, and script locations. The entries in this array are created by the web server.

'PHP_SELF'


The filename of the currently executing script, relative to the document root. For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar would be /test.php/foo.bar.

Ex-If  Page address is 'localhost/auto/8-00/test.php'

<?php
echo $_SERVER['PHP_SELF'];
?> 

Output :

/auto/8-00/test.php

'SERVER_NAME'

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.

Ex-If  Page address is 'localhost/auto/8-00/test.php'

<?php
echo $_SERVER['SERVER_NAME'];
?> 

Output :

localhost

'SERVER_SOFTWARE'

It provide information about server softwares.


Ex-

<?php
echo $_SERVER['SERVER_SOFTWARE'];
?> 

Output :

Apache/2.2.12 (Win32) DAV/2 mod_ssl/2.2.12 OpenSSL/0.9.8k mod_autoindex_color PHP/5.3.0 mod_perl/2.0.4 Perl/v5.10.0

No comments:

Post a Comment