Skip to content
Readerstacks logo Readerstacks
  • Home
  • Softwares
  • Angular
  • Php
  • Laravel
  • Flutter
Readerstacks logo
Readerstacks
Request Method

Difference between $_POST $_GET and $_REQUEST in PHP

Aman Jain, August 19, 2021November 8, 2023

PHP gives there is 3 types of request methods to by which client can send information to server. In this article we will learn difference in get vs post and also in request. So, Methods are as follow

  1. $_POST
  2. $_GET
  3. $_REQUEST

1. $_POST Request Method

$_POST is used to fetch the post request data from the client end.

Example of client and server request in php

<form action="/action_page.php" method="post">
  <label for="fname">First name:</label>
  <input type="text" id="fname" name="fname"><br><br>
   
  <input type="submit" value="Submit">
</form>

File: index.php

<?php 
$first_name = $_POST['fname'];

File: action_page.php

2. $_GET Request Method

$_GET is used to fetch the query params from URL and form.

<form action="/action_page.php" method="get"> // here method is get
  <label for="fname">First name:</label>
  <input type="text" id="fname" name="fname"><br><br>
   
  <input type="submit" value="Submit">
</form>

we can also use it in URL

https://your_url.com/index.php?post=115&action=edit

In php

<?php 

$first_name = $_GET['fname'];  //form index.php
//url
$post= $_GET["post"];

$action=$GTE["action"];

File: action_page.php

3. $_REQUEST Method

$_REQUEST is combination of both $_GET and $_POST. so we can fetch both type of request using $_REQUEST.

<?php 

$first_name = $_REQUEST['fname'];  //form index.php

//url
$post= $_REQUEST["post"];

$action=$_REQUEST["action"];

Difference between GET vs POST

Here is table for get vs post

GETPOST
BACK button/ReloadNo LossPost Data will resubmit
BookmarkedWe can bookmark easilyCannot
CachedYesNo
Encoding typeapplication/x-www-form-urlencodedapplication/x-www-form-urlencoded or multipart/form-data. Use multipart encoding for binary data
HistoryParameters stay in urlLost
Restrictions on data lengthYes, maximum URL length is 2048 charactersNo restrictions
Restrictions on data typeOnly ASCII characters allowedNo restrictions
SecurityLessHigh
VisibilityYes, visible in urlNo
Difference between get and post

Difference between $_GET and $_REQUEST

As i mentioned above $_REQUEST is combination of both post and get. Hence, its only exist in PHP and can be used as both get and posy methods.

Also Read : How to connect PHP to MySQL ?

Share this:

  • Facebook
  • X

Related

Uncategorized

Post navigation

Previous post
Next post

Related Posts

Uncategorized Call Controller Method from Another Controller in Laravel

How to Call Controller Method from Another Controller in Laravel ?

December 2, 2023December 2, 2023

In this article we will learn Call Controller Method from Another Controller in Laravel. Sometimes we need to access the controller method from another controller to save the same code on multiple locations. Best way to achieve it is using create a separate service class or trait in PHP so…

Share this:

  • Facebook
  • X
Read More
Uncategorized update page data without reload

How to update page data without reload in jQuery?

October 24, 2021November 17, 2023

If you are beginner then this post is for you. For showing the new content on page without refresh we will use JQuery Reload Page without Refresh and server side PHP. In this article, I will demonstrate to show the latest content from server without refreshing the page. This is…

Share this:

  • Facebook
  • X
Read More
Uncategorized rollback specific migration in laravel

How to rollback specific migration in laravel ?

March 6, 2022November 8, 2023

In this article we will learn rollback specific migration in laravel, in our recent article i wrote about creating migration in laravel and sometimes after creating migration we want to rollback specific migration laravel so in this article i will show you to rollback a specific migration in laravel. Laravel…

Share this:

  • Facebook
  • X
Read More

Leave a ReplyCancel reply

Aman Jain
Aman Jain

With years of hands-on experience in the realm of web and mobile development, they have honed their skills in various technologies, including Laravel, PHP CodeIgniter, mobile app development, web app development, Flutter, React, JavaScript, Angular, Devops and so much more. Their proficiency extends to building robust REST APIs, AWS Code scaling, and optimization, ensuring that your applications run seamlessly on the cloud.

Categories

  • Angular
  • CSS
  • Dart
  • Devops
  • Flutter
  • HTML
  • Javascript
  • jQuery
  • Laravel
  • Laravel 10
  • Laravel 9
  • Mysql
  • Php
  • Softwares
  • Ubuntu
  • Uncategorized

Archives

  • December 2023
  • November 2023
  • October 2023
  • July 2023
  • March 2023
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Recent Posts

  • How to Call Controller Method from Another Controller in Laravel ?
  • How to Get Domain Name in Laravel ?
  • How to Append Query String to Route in Laravel ?
  • How to Append URL Query Params to Pagination Laravel ?
  • How to Get Today Records in Laravel ?
©2023 Readerstacks | Design and Developed by Readerstacks
Go to mobile version