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

PHP Superglobal - $_POST

<html>
<body>

<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
  Name: <input type="text" name="fname">
  <input type="submit">
</form>

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
  // collect value of input field
  $name = $_POST['fname'];
  if (empty($name)) {
    echo "Name is empty";
  } else {
    echo $name;
  }
}
?>

</body>
</html>
Comment

variable superglobale php

echo "dsd";
Comment

PREVIOUS NEXT
Code Example
Php :: install mess detector 
Php :: php get and print file contents 
Php :: Notice: ob_end_flush(): failed to send buffer of zlib output compression (1) in 
Php :: how to create new project in laravel 
Php :: woocommerce get product category name by id 
Php :: read file data using php 
Php :: disable quantity field in woocommerce 
Php :: loop index foreach laravel 
Php :: get table name from model laravel 
Php :: change date format php 
Php :: laravel api too many requests 
Php :: [DoctrineDBALDBALException]Unknown database type enum requested, DoctrineDBALPlatformsMySqlPlatform may not support it. 
Php :: How to pass JavaScript variables to PHP? 
Php :: phpmyadmin first login 
Php :: woocommerce product object 
Php :: how to upload pdf file using php 
Php :: laravel sort by numbers 
Php :: laravel migrate seed 
Php :: json url decode php 
Php :: create foreign key phpmyadmin 
Php :: composer create project version 
Php :: format money with commas in php 
Php :: [InvalidArgumentException] Package mongodb/mongodb has requirements incompatible with your PHP version , PHP extensions and Composer version: - mongodb/mongodb 1.12.0 requires ext-mongodb ^1.13.0 but it is not prese nt. 
Php :: how add field to table by another migration in laravel 
Php :: how to use md5 in php 
Php :: turnery expression php 
Php :: make model inside module laravel 
Php :: php expire a session 
Php :: php in html attributes 
Php :: array reduce associative array php 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =