I want to know what are the usages of $_SERVER and $_ENV in php. Or for what they can be used.

I want to know what are the usages of $_SERVER and $_ENV in php. Or for what they can be used.

Both $_SERVER and $_ENV give you information on the environment your PHP script is running in.

$_SERVER is an array of useful information about the server, and HTTP Request.

An example use is in constructing the full HTTP Request made to the server as this class does:
http://www.daniweb.com/code/snippet616.html

Another use would be to get the clients, IP address:

echo $_SERVER['REMOTE_ADDR'];

$_ENV contains information about the environment in which the PHP parser is running.
It would probably be more appropriate when running PHP as a shell script under the Command Line (CLI).

How they differ is in that $_SERVER presents information assuming PHP was invoked as a webpage, and thus has info on the HTTP request, and the server environment. (which is the most common use of PHP)
$_ENV is a bit more generic, and the information in it would be dependent on the shell that the PHP parser was executing under.

Try doing a var_dump($_SERVER) and a var_dump($_ENV); in your PHP script to see the actual values they contain when your script executes. If you have shell access to the server running your PHP then try executing the php script from the command line to see how it differs.

commented: Awesome, really Impressed with her knowledge. +1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.