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…

How to implement A2F using Own Development in NodeJS in a Scriptcase application

A2F using Own Development in NodeJS A2F: In a previous article, we talked about Swivel as an extern...

Specialists or generalists, who gets a better advantage by using Scriptcase?

Hey there! Today  we will figure what are the ideal profiles for those who wish to take advantage o...

Disabling autofill and autocomplete Chrome browser in login screens

Hello, here I want to show an alternative to disable the autofill and autocomplete of the chrome bro...

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.