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…

“We have developed the Connected Citizen Card, which assists public administrators in decision-making and policy creation.”(Assist Soluções em TI)

Check below how Assist Soluções em TI used Scriptcase to modernize and streamline the development...

AI-Driven Software Development: The Role of ChatGPT

In the rapidly evolving world of technology, artificial intelligence (AI) is playing an increasingl...

Low-Code: The Key to Accessible Digital Transformation

Digital transformation is imperative for companies wishing to remain competitive in the current era...

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.