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.

Check out more content on our blog!
Learn all about Scriptcase.

By ,

June 16, 2015

a

You might also like…

How to Create and Read QR Codes and Barcodes

“Point your cell phone camera to read the QR code.” This phrase has been increasingly recurring...

Why is Low-Code essential for any business?

Low-Code is the IT term that refers to the process of using little code to develop software and app...

“The Preventus Medical Center system has more than 222,000 patients and 115 professionals.” (DRey Solutions)

Check out how DRey Solutions uses Scriptcase to streamline and synthesize the process of maintenanc...

You might also like…

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.