Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php superglobals

#Superglobal

$_SERVER Superglobal
Superglobals were introduced in PHP 4.1.0, and are built-in variables 
  that are always available in all scopes. Basically system variables.
https://www.w3schools.com/php/php_superglobals.asp

Note: $_SERVER Superglobal  -- tells a little about the server and 
  the client

==============
#Example index.php
<?php include 'server-info.php';?>
<!DOCTYPE html>
<html>
<head>
    <title>System Info</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
</head>
<body>
<div class ="container">
    <h1>Server & File Info</h1>
    <?php if($server): ?>
    <ul class="list-group">
    <?php foreach($server as $key => $value): ?>
        <li class="list-group-item">
            <strong><?php echo $key; ?>: </strong>
            <?php echo $value; ?>
        </li>
    <?php endforeach; ?>
    </ul>

    <?php endif; ?>

    <h1>Client Info</h1>
    <?php if($client): ?>
    <ul class="list-group">
    <?php foreach($client as $key1 => $value1): ?>
        <li class="list-group-item">
            <strong><?php echo $key1; ?>: </strong>
            <?php echo $value1; ?>
        </li>
    <?php endforeach; ?>
    </ul>

    <?php endif; ?>

</body>
</html>
==================
#Example server-info.php
<?php
    # $_SERVER SUPERGLOBAL

    //Create Server Array
    $server =[
        'Host Server Name' => $_SERVER['SERVER_NAME'],
        'Http Host' => $_SERVER['HTTP_HOST'],
        'Server Software' => $_SERVER['SERVER_SOFTWARE'],
        'Document Root' => $_SERVER['DOCUMENT_ROOT'],
        'Current Page' =>  $_SERVER['PHP_SELF'],
        'Script Name' =>  $_SERVER['SCRIPT_NAME'],
        'Absloute Path' =>  $_SERVER['SCRIPT_FILENAME']

    ];

    echo $server['Host Server Name'];
    echo $server['Http Host'];
    echo $server['Server Software'];
    echo $server['Document Root'];
    echo $server['Current Page'];
    echo $server['Script Name'];
    echo '<br>';
    //also can show it all
    print_r($server);

    //Creat Client Array
    $client = [
        'Client System Info' => $_SERVER['HTTP_USER_AGENT'],
        'Client IP' => $_SERVER['REMOTE_ADDR'],
        'Remote Port' => $_SERVER['REMOTE_PORT']

    ];
    echo '<br>';
    echo '<br>';
    print_r($client);

?>
Comment

PHP Superglobal - $GLOBALS

<?php
$x = 75;
$y = 25;
 
function addition() {
  $GLOBALS['z'] = $GLOBALS['x'] + $GLOBALS['y'];
}
 
addition();
echo $z;
?>
Comment

PREVIOUS NEXT
Code Example
Php :: laraval routing 
Php :: guzzle login example 
Php :: wordpress get all published post 
Php :: The last ship -inurl:(htm/html/php/pls/txt) intitle:index.of "last modified" (mp4/wma/aac/avi) 
Php :: PHPDoc @method 
Php :: what is Trustproxies handle in laravel 
Php :: array filter php get first object 
Php :: ModelNotFoundException 
Php :: displaying dates using php code 
Php :: laravel use cache 
Php :: API call in PHP using cURL 
Php :: php delete file 
Php :: php versions and features 
Php :: controller class does not exist laravel 
Php :: global variable in laravel 
Php :: php backend generator 
Php :: php read excel file 
Php :: error handling in laravel 
Php :: create xml php 
Php :: laravel join 2 tables eloquent 
Php :: upload image in laravel 
Php :: php array form 
Php :: why php is not using datatype 
Php :: export laravel path fedora 
Php :: elasticsearch php filter range 
Php :: wp wc php use comma separated thousands 
Php :: Array unpacking support for string-keyed arrays - PHP 8.1 
Php :: Check box group submit (php) 
Php :: wordpress add_action echo on edit page 
Php :: Issue with Generating Random Numbers using Laravel contains vs foreach loop 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =