PHP Tutorial





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
PHP Topics
Introduction Introduction
Syntax Syntax
Data Types Data Types
Operators Operators
Control Structures Control Structures
Functions Functions
Pre-defined Function Pre-defined Function
Calendar Functions Calendar Functions
Date and Time Date and Time
Array Functions Array Functions
Array List Array Functions List1
Array Function List Array Functions List2
Math Functions Math Functions
PHP MYSQL Functions PHP Mysql Functions
File Handling File Handling
Error Handling Error Handling
DB Size DB Size
PHP Mail PHP Mail
String Tokens String Tokens
String Functions String Functions
String Functions List String Functions List1
String Functions List2 String Functions List2
Session Functions Session Functions
Cookies Functions Cookies Functions
Form Variables Form Variables
Running PHP from JS Running PHP from JS
Array To JS Array To JS
JS Array Array to PHP
Encryption Encryption
Common Header Common Header
Forums Ask Your Doubts
Scraps More about PHP
Feedback Feedback
 




REQUEST Method in PHP


Tutorials »Php »

Topic

How to use REQUEST method in PHP to get form values?



Explanation

This is a 'superglobal', or automatic global variable. $_REQUEST is an associative array consisting of the contents of $_GET, $_POST, and $_COOKIE ie, it is available in all scopes throughout a script.

Example:  Create a simple form which contains variables handled by GET,POST method and COOKIE variable.

A Simple Form:
Name:

Email:


When the user fill the form and click submit button the form will be submitted to request.php.

Coding to create a simple form
<?php
setcookie("user", "Alex");
foreach($_REQUEST as $val)
{
echo"$val";
echo"<br>";
}
?>
<form action="request.php?age='25'&city='cbe'" method="POST">
Name: <input type="text" name="name">
Email: <input type="text" name="mail">
<input type="submit" value="Submit">
</form>

In the above code form filed variable such as "name" and "mail" is handled by POST method as we mentioned method=POST. Variables such as "age" and "city" are passed through url so it will be accessed only by GET method and here cookie is set for variable "user " with value "Alex" by using setcookie function. Save above code with the name getvariable.php.

When the user enter the values for name and email and clicks the submit button, variables with the values are submitted to request.php. Here variables handled by different methods are printed. Thus $_REQUEST variable is an associative array used to get the values of POST,GET and COOKIE variables.

RESULT





Other Links

web hosting