Total Pageviews

Showing posts with label REQUEST differences. Show all posts
Showing posts with label REQUEST differences. Show all posts

Difference between $_GET, $_POST and $_REQUEST

Written By Naveen on Tuesday, November 29, 2011 | 3:02 AM

$_GET, $_POST and $_REQUEST  all these variables are predefined variables in php. Normally we have 2 methods to send the data to one page to another page. Those methods are nothing but GET and POST methods. Using this variable we can get the data by specifying the variable name for example, $_GET['name'], $_POST['email'] and $_REQUEST['phone'].

Using GET method:
we can get the data from URL
Example: www.example.com/index.php?name=phptag
Now from the above URL if you want to get the phptag value see the code below

<?php

$name = $_GET['name'];
//or
$name = $_REQUEST['name'];

?>

Using POST method:
we can get the in hidden mode, that means we cannot see the data in URL it will carry through the headers.
Normally we can use the post method by implementing the html form's see the code below

<form name='phptag' method='post'>
     <input type='text' name='name' value='phptag'>
     <input type='submit' name='demo' value='Click' >
</form>
<?php

$name = $_POST['name'];
//or
$name = $_REQUEST['name'];

?>

In the above examples the common thing that we have used is $_REQUEST which means it can be used for both GET and POST methods to get the data.
3:02 AM | 15 comments | Read More