Originally, in PHP language some variables are predefined and can be accessed anywhere in the script, without the need to declare them. These variables are called superglobals and offer the programmer a number of important information about  customers and also about the server where the application is allocated. Following, we present some of these variables and understand how they interact within the application.

 

$_SERVER

In this array are stored information related to the server, such as name and IP address, for example. To access the information stored in the array, simply perform the request by the name of the position:

<?php
echo $_SERVER[‘SERVER_NAME’];
?>

The most diverse information can be found when using the $ _SERVER array. So all the names and values by position can be found in the official documentation of the resource.

 

$_GET

This array is used when you need to work with querystrings or variables passed via HTTP GET method. When working with querystrings the URL, you can then recover the amount from the name and use it within the local script:

<?php
echo ‘Hello ‘ . htmlspecialchars($_GET[“name”]) . ‘!’;
?>

Understanding that the user accessed the url http://example.com/?name=Hannes, the information that will be printed on screen will be: Hello Hannes!

$_POST

This array is used in cases when you need to work with querystrings or variables passed via HTTP POST method. When working with querystrings in the URL, you can recover the value from the name and use it within the local script:

<?php
echo ‘Hello ‘ . htmlspecialchars($_POST[“name”]) . ‘!’;
?>

 

Understanding that the user accessed the url http://example.com/?name=Hannes, the information that will be printed on screen will be: Hello Hannes!

 

$_COOKIE

This array accesses the information that was stored on the client through the use of cookies.

<?php
echo ‘Hello ‘ . htmlspecialchars($_COOKIE[“name”]) . ‘!’;
?>

 

Understanding that a cookie was stored on the client machine before, the example will show on screen the following information: Hello Hannes!

The presented superglobal variables are frequently used in web development environments – however, a number of others are available for any situations. To know each of them and how they can be used, just visit the official documentation available at PHP.net website.

You might also like…

PROCESAMIENTO AJAX EN SCRIPTCASE

Ajax en los formularios de Scriptcase puede usarse para recargar un campo de tipo de select basado e...

IMPORTAR IMAGENES DE LA BASE DE DATOS Y UTILIZAR CLASES DE BOOSTRAP

Como muchas personas ya saben, Bootstrap es una biblioteca de front-end libre y de código abierto p...

TENDENCIAS DE DESARROLLO WEB PARA 2017

Usted verá en este post tendencias para 2017 en Diseño Web, en el medio digital y en el desarrollo...

Comment this post

Get new posts, resources, offers and more each week.

We will use the information you provide to update you about our Newsletter and Special Offers. You can unsubscribe any time you want by clinck in a link in the footer of any email you receive from us, or by contacting us at sales@scriptcase.net. Learn more about our Privacy Police.