Server Variables

Getting Started with PHP
Getting Started with PHP : Home
Hello World
Data Types in PHP
Variables in PHP
Operators in PHP
Decision Making in PHP
Iterations in PHP
Functions in PHP
Arrays in PHP
Strings in PHP
Object Oriented PHP
Classes and Objects
Object Interfaces
Static and Final
Advanced Features in PHP
Session in PHP
Cookies in PHP
Server Variables

$_SERVER contains information about the server which is provided by the server you are visiting and may vary. It is quite possible that one server is not providing all the variables we will discuss and also possible that some server is providing some variables specific to the server.

PHP_SELF : Will give you the name of the file with it's directory. You will understand that better with a code.

HTTP_HOST : Give the header of the current requests.

SERVER_NAME : Will give you the name of server on which the php is executing

REQUEST_METHOD : The method through which the current method was executed will be given.

HTTPS : A non empty value is set if the the connection is secure i.e HTTPS.

SERVER_ADDR : It will give the IP address of the server i.e the server which is executing the scripts.

There are other lots of other variables but these are some most commonly used.

echo $_SERVER['PHP_SELF']."<br>";
echo $_SERVER['HTTP_HOST']."<br>";
echo $_SERVER['SERVER_NAME']."<br>";
echo $_SERVER['REQUEST_METHOD']."<br>";
echo $_SERVER['SERVER_ADDR']."<br>";



The output may look bizarre because it was run on localhost.

Login to Track Your Progress