PHP $_REQUEST, $_GET and $_POST Variables


PHP $_REQUEST, $_GET and $_POST Variables
php get post request variables

This Are the PHP GLOBAL Variable in PHP Which helps to get value from one page to other or in Html Form Submitting or Passing Value with URL Then We Use This Variables to Get the values.

$_GET

$_GET - > This variable is used when we submitting our form by using method is equal to get or opening any page with passing value in url like ( hello.php?id=1 ). Then we get the Value by using $_GET[‘id’] . When We used get method in form Submitting then we see our key and Value pair in url.

What is key and value?

Example : hello.php?id=1

Here id is key and 1 is value.

$_POST

$_POST - > This variable is used when we submitting our form by using method is equal to post . When We used post method in form Submitting then we cannot see our key and Value pair in url.

Example : -

code 1. hello.html

<html>
<head>
<title>Post Example in PHP </title>
</head>
<body>
<form action=”post.phpmethod=”post”>
Name : <input type=”textname=”name”>
<input type=”submitvalue=”submit”>
</form>
</body>
</html>
Code 2. post.php
<?php
echo $_POST[‘name’];
?>

$_REQUEST

$_REQUEST - > This variable is works both with get and post when we submitting our form by using method is equal to get or post Or opening any page with passing value in url like ( hello.php?id=1 ). Then we get the Value by using $_REQUEST[‘id’] . REQUEST is Really Great Variable Works with Both Get and Post We dont care about method When we using REQUEST.

Example : -

code 1. hello2.html

<html>
<head>
<title>Request Example in PHP </title>
</head>
<body>
<form action=”request.phpmethod=”post”>
Name : <input type=”textname=”name”>
<input type=”submitvalue=”submit”>
</form>
</body>
</html>
Code 2. request.php
<?php
echo $_REQUEST[‘name’];
?>

Thank You
Previous Post
Next Post

post written by:

0 comments: