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

variable superglobale php

echo "dsd";
Comment

PREVIOUS NEXT
Code Example
Php :: generate random number of 4 digit in php 
Php :: get current date laravel 
Php :: define home url wp 
Php :: php get current year 
Php :: php mysqli connection check 
Php :: time to load php page 
Php :: laravel validate number to be at least 3 digits 
Php :: php request uri 
Php :: php pdo get database name 
Php :: htaccess cakephp 
Php :: laravel withtrashed 
Php :: wordpress PHPMailer config 
Php :: php get client ip address 
Php :: display errors in codeigniter 
Php :: twig jsoncencode 
Php :: strtolower php 
Php :: phpMyAdmin is not able to cache templates 
Php :: total no of occurances in string php 
Php :: running laravel as host 
Php :: How to check current URL inside @if statement in Laravel 
Php :: PHP wordwrap() Function 
Php :: laravel model insert 
Php :: old function use in checkbox selected in laravel blade 
Php :: collection laravel filter 
Php :: create a exporter in laravel command 
Php :: php copy url 
Php :: clear file contents php 
Php :: laravel get query output 
Php :: php array_sum 
Php :: mkdir() permission denied laravel 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =