Super Global Varibles in Php
*********************************
super global varibles are used predefined in built special varibles used to
get the value from any scope
scopes
1. local scope
2. global scope
3. cleint scope
4. server side scope
There are Two types of super global variable
1. mangled variable :_ will be used prefix example
$_POST
$_GET
$_SERVER
$_REQUEST
2. unmangled varible :they donot start from _ as prefix
$GLOBALS
These superglobal variables are:
$GLOBALS
$_SERVER
$_GET
$_POST
$_FILES
$_COOKIE
$_SESSION
$_REQUEST
$_ENV
Superglobal = unmangled + mangled
Note: Name Mangling
class Test{
public $name;
protected $__class;
private $_marks;
}
There Context are super means they can be session access any where
Post-Mortum of Super Global Varibles
$GLOBALS:
it convert any local varible to super global variable and this varible
is formed such that it becomes unmangled varible
$_GET : to recive varaible or formdata from GET REQUEST
Can be recived if Query is generated
Query String each varible will a key in $_GET
?name=ravi&class=12
$name = $_GET['name'];
$class = $_GET['class'];
echo $name; //ravi
echo $class;
Invalid :
$name = $_POST['name'];
echo $name; Undefined Index name Notice Error
$_POST : to receive varible or formdata from POST REQUEST
$_REQUEST : to recive varible from formdata with Any Request $_GET or $_POST
$_Request:: Varible Is indepedent of Request Type or it can handle both the Request GET and POST
$_REQUEST = $_GET + $_POST
?[n>1]+ ?[n=0]
if ?n>=1 get key1 $_GET = $_REQUEST
if ?n=0 POST key1 $_POST = $_REQUEST
Example:
How to send both request : PATCH(update single data) Request or PUT Request (update multiple data)
action = "update.php?id=10"
update <tablename> set name = '$name' where id='$id'; [PATCH]
| |GET
post
update <tablename> set name = '$name',class = '$class',mobile='$mobile' where id='$id'; [PUT]
How to generate Patch Request and Put Request.
we know that if we want to update and data in the database then we have to
send either put request or patch request.
fully update => [Put] request
partial update => [Patch] request
Query for PUT:
Database Schema
---------------------------
Table : student |
---------------------------
id|name | class |marks |
1001|ravi | 12 | 00 |
2002|chavi| 10 | -10 |
---------------------------
update student set marks='100' where id = '1';
Patch Request
Fully update => fully changed in value of auxillary Columns set.
auxillary column set = total columns - (No of Pk Or Composite Key)
if n=3 request Put
if n<3 request patch
In order to sent both the request use ?query string and method = "post"
?query string keyname = which is unique and will not be changed.
?id=1111
post => whose value can be changed name,class,marks
$_SERVER : it is the super global varibale used to get the server configuration
like hostname,host agent, server variables, query string, methods , type
of request,types of headers,..etc,server signature.
How to print multi dimensional array
echo "<pre>";
echo print_r($_SERVER);
echo "</pre>";
exit;
0 Comments