How To Use The $_REQUEST Variable In PHP

How To Use The $_REQUEST Variable In PHP

·

1 min read

In this tutorial, you will be learning about the $_REQUEST[] variable.

$_REQUEST is a PHP superglobal variable that lets you access data that's been sent to the page from another page. The difference with $_POST[] is that $_REQUEST[] can access data sent via either the POST or the GET method, while $_POST[] or $_GET[] can only access data sent via their own method type. So to illustrate this, let's have a look at the example below. Example

a.php

<html>
<head><title></title></head>
<body>
<form action='a.php' method='POST'>
<input type='text' name='a'>
<br>
<input type='submit' value='submit'>
</body>
</html>

b.php

<?php
echo $_REQUEST['a'];
?>

Result

1.png

<?php 
echo $_POST["a"];
?>

The above code would have yield the same results as if you used $_REQUEST['a']. However, the code below will not work.

<?php
echo $_GET["a"];
?>

You cannot access POST data using the $_GET[] variable.