Superglobal variables are important facilitators on programming when using the PHP language. For example, the $_REQUEST array that stores information of three other superglobal variables: $ _GET, $ _set and $ _POST.

$_REQUEST PHP

The variables available in $ _REQUEST array are available via request input mechanisms, POST, and COOKIE, and may be modified by a remote user. Thus, there is a need to validate the information and treat it. The presence and order of variables listed in this array is defined according to the PHP configuration directive variables_order.

Despite using the same input mechanisms, the variable $ _REQUEST is different from the $ _GET and $ _POST. Thus, when handling them at runtime, the variable $ _REQUEST is not modified:

<?php

$_GET[‘foo’] = ‘a’;
$_POST[‘bar’] = ‘b’;
var_dump ($ _ GET); // The element ‘foo’ returns the string ‘a’ in the $ _GET

var_dump ($ _ POST); // The ‘bar’ element returns the string ‘a’ in the $ _POST

var_dump ($ _ REQUEST); // None of the elements contained in the variable $ _REQUEST

?>

From the type of request, you can then find the element positioned in the array and use it after, as shown in the following example:

<?php
if ($_SERVER[“REQUEST_METHOD”] == “POST”) {

$name = $_REQUEST[‘fname’];
if (empty($name)) {
echo “No stored name.”;
} else {
echo “The stored name is: “.$name;
}
}
?>

After identified the type of request, the variable $name takes the value of the position. In the example, the position value ‘fname’ is recovered. From this, the validation is done by printing their name, if it is not empty.

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.