$_COOKIE

A cookie is used to identify a user. A cookie is a small file that the server embeds on the user’s computer. Each time the same computer requests a page with a browser, it will send the cookie too. With PHP, you can both create and retrieve cookie values.

Example:
Code:

$expire=time()+60*60*24*30;
setcookie("user", "Watson", $expire);
// Print a cookie
echo $_COOKIE["user"];

Output:

Watson

Explanation:

The first time the page is loaded the cookie hasn’t been created . When the page is reloaded the value is printed.

$_SESSION

Description:

$_SESSION variable is used to store and retrieve session variables.

Example:
Code:

session_start();
//   without store session data
$_SESSION['views']=1;

//retrieve session  data
echo "views=". $_SESSION['views'];

Output:

views=1

$_REQUEST

Syntax: $_REQUEST

Description:

The PHP built-in $_REQUEST function can be used with both the GET and POST methods.

Example:
Code:

Name: Age:

Explanation: HTML code.

Example:
Code:

  echo $_REQUEST["fname"];
  echo$_REQUEST["age"]; 

Output:

Watson
29.

$_FILES

Syntax: $_FILES

Files can be uploaded from a browser to the server with forms using the “file” input type.

Example:
Code:

File:

Explanation: HTML code for file.

Example:
Code:


print_r($_FILES);

Output:

Array (
[file] => Array (
[name] => Desert.jpg
[type] => image/jpeg
[tmp_name] => C:\wamp\tmp\phpD31E.tmp
[error] => 0
[size] => 845941 ) )

Explanation: It gives information about uploaded files.

$_POST

Syntax: $_POST

Description:

The function is used to collect values from a form sent with method=”post”.

Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send.

This is a ‘super global’, or automatic global, variable.It means that it is available in all scopes throughout a script. You don’t need to do a global $_POST; to access it within functions or methods.

Example:
Code:

Name: Age:

Explanation: HTML code.

Example:
Code:

 
 echo $_POST["fname"]; 
 echo $_POST["age"];    

Explanation: PHP code.

Output:

Sachin!
36.

Page 1 of 212
eXTReMe Tracker