Superglobal variable in php

PHP Global Variables – Superglobals

Some predefined variables in PHP are “superglobals”, which means that they are always accessible, regardless of scope – and you can access them from any function, class or file without having to do anything special.
The PHP superglobal variables are:

  • $_SERVER
  • $_REQUEST
  • $_POST
  • $_GET
  • $_FILES
  • $_ENV
  • $_COOKIE
  • $_SESSION
$data = $_GET['name'];
$data = $_POST['name'];
$data = $_REQUEST['name'];
index.php ($_SESSION)
<?php
session_start();
$_SESSION['name'] = 'Pankaj Kumar Loniya';
?>
submit.php ($_SESSION)
<?php
session_start();
echo $_SESSION['name'];
?>
index.php ($_FILES)
<form method="post" action="submit.php" enctype="multipart/form-data">
<input type="file" name="photo">
<button type="submit">submit</button>
</form>
submit.php ($_FILES)
<?php
$photo = $_FILES['photo'];
print_r($photo);
?>

Leave a Reply