QUIZGUM

Coding Class

Quizgum : environment variables

Environment variables

This tutorial explains environment variables.
So let's start the lesson.
Variables in PHP have variables coming from outside of the variables we create and use.
In particular, there are many variables associated with the system. These variables are called environment variables.
You can use the phpinfo() function to view many environment variables, which contain information about the system.

/htdocs/phpinfo.php

<?php
    phpinfo();
?>

atom

php image

result

php image

The functions apache, session, php etc. are listed.
When using environment variables, they should be written in capital letters.
Learn about frequently used environment variables

Environment variables attribute value

$_SERVER['SERVER_NAME']

Server Name

$_SERVER['SERVER_PROTOCOL']

Server Protocol

$_SERVER['SERVER_PORT']

Server Port

$_SERVER['REMOTE_ADDR']

Client's IP Address

$_SERVER['SCRIPT_FILENAME']

Absolute path of running file

$_SERVER['SCRIPT_NAME']

Name of the file being run

$_SERVER['PHP_SELF']

Name of the currently running program
(php related environment variables)

So let's finish this lesson by testing the above functions.
Enter the source as shown below.

/htdocs/ev.php

<?php
    echo "Common Environment Variable Example <br>";

    echo "1. the Name of Server : ".$_SERVER['SERVER_NAME']." <br>";
    echo "2. the Protocol of Server : ".$_SERVER['SERVER_PROTOCOL']." <br>";
    echo "3. the Port Number of Server : ".$_SERVER['SERVER_PORT']." <br>";
    echo "4. the Client's IP Address : ".$_SERVER['REMOTE_ADDR']." <br>";
    echo "5. the path of This File : ".$_SERVER['SCRIPT_FILENAME']." <br>";
    echo "6. the name of file : ".$_SERVER['SCRIPT_NAME']." <br>";
    echo "7. the name of This Program : ".$_SERVER['PHP_SELF']." <br>";
?>

atom

php image

result

php image