SlideShare a Scribd company logo
2
Most read
3
Most read
PHP Tutorials By Vineet Kumar Saini

                        $_GET and $_POST in PHP

Introduction

Using the GET and POST methods, the browser client can send data to the web server. In
PHP the GET and POST methods are used to retrieve information from forms, such as user
input. Get and Post are methods used to send data to the server. These methods are used
for data handling in forms. Where each method varies a little in the way they work.

GET Method

In the GET method, we can also send data to the server. But when using the GET method
we can't send the login details with a password because it is less secure (information sent
from a form with the GET method is visible to everyone). We can say that the GET method
is for getting something from the server; it doesn't mean that you cannot send a parameter
to the server.

The main points about the GET method are as follows:

      The GET method is used to collect values in a form.
      GET method is used when the URL is sent to the server.
      GET method has limits on the amount of information to send because URL lengths
       are limited.
      The Get method is used to retrieve web pages from the server.
      The GET method is the default method for many browsers.
      Data is sent as a part of the URL in 'name-value' pairs.
      In the GET method page and the encoded information are separated by the question
       mark (?) sign.
      In the GET method, the browser appends the data onto the URL.
      The Get method is less secure because information sent from a form with the GET
       method is visible to everyone (it will be displayed in the browser's address bar) .
      GET can't be used to send binary data, like images or word documents, to the
       server.

Example

First of all we create a PHP file which is called by the HTML page in later.

<html>
<body bgcolor="pink">
Welcome <?php echo $_GET ["Name"]; ?>.<br/>
You are <?php echo $_GET ["Class"]; ?> Qualified !!
</body>
</html>

The above file is to be saved with the name "get.php", which is called by the HTML page
later.

<html>
<body bgcolor="pink"><table>
PHP Tutorials By Vineet Kumar Saini

<form action="get.php" method="get">
<tr><td>Name: <input type="text" name="Name" /></td></tr>
<tr><td>Class : <input type="text" name="Class" /></td></tr>
<input type="submit" " value="Submit"/>
</form>
</body>
</html>

This file is saved as "get.html". In this file get.php is called.

Output

You will put the URL in the web browser like as: http://localhost/FolderName/get.html.




Now you will fill text like as name and class. When you click on the submit button then you
will see your browser URL changed. You can see in the following image.
PHP Tutorials By Vineet Kumar Saini

POST Method

In PHP $_POST variable is used to collect values from a form sent with method="post". In
the POST method one can request as well as send some data to the server. The POST
method is used when one can send a long enquiry form. Using the POST method the login
details with password can be posted because it is secure (information sent from a form with
the POST method is invisible to everyone).

The main points about POST method are as follows:

      The POST method is used to collect values from a form.
      The POST method has no limits on the amount of information to send because URL
       lengths are unlimited.
      The POST method is the not default method for many browsers.
      In the POST method, the page and the encoded information are not separated by the
       question mark (?) sign.
      In the POST method, the browser doesn't append the data onto the URL.
      The POST method is secure because information sent from a form with the GET
       method is invisible to everyone.
      The POST method can be used to send binary data, like images or Word documents,
       to the server.
      In the POST method, the data is sent as standard input.
      The POST method is slower than the GET method.
      PHP provides the $_POST associative array to access all the information sent using
       the GET method.

Example

First of all we create a PHP file which is called by the HTML page later.

<html>
<body bgcolor="pink">
Welcome <?php echo $_POST ["Name"]; ?>.<br/>
You are <?php echo $_POST ["Class"]; ?> Qualified !!
</body>
</html>

The above file is saved with the "post.php" name, which is called by the HTML page later.

<html>
<body bgcolor="pink">
<table>
<form action="post.php" method="post">
<tr><td>Name: <input type="text" name="Name" /></td></tr>
<tr><td>Class : <input type="text" name="Class" /></td></tr>
<input type="submit" " value="Submit"/>
</form>
</body>
</html>

This file is saved as "post.html". In this file post.php is called.
PHP Tutorials By Vineet Kumar Saini




Now you will fill text like as name and class. When you click on the submit button then you
will see your browser URL is not changed. You can see in the following image.




$_REQUEST Variable

The $_REQUEST variable is also used to send data to the server. The $_REQUEST variable is
a predefined variable in PHP. Which keeps the $_GET, $_POST and also $_Cookie variable.
This variable is used to collect data of the form sent by the GET and POST methods.

First of all we create a PHP file which is called by the HTML page later.

<html>
<body bgcolor="pink">
Welcome <?php echo $_REQUEST ["Name"]; ?>.<br/>
You are <?php echo $_REQUEST ["Class"]; ?> Qualified !!
PHP Tutorials By Vineet Kumar Saini

</body>
</html>

The above file is saved with the "request.php" name, which is called by the HTML page
later.

<html>
<body bgcolor="pink">
<table>
<form action="request.php" method="post">
<tr><td>Name: <input type="text" name="Name" /></td></tr>
<tr><td>Class : <input type="text" name="Class" /></td></tr>
<input type="submit" " value="Submit"/>
</form>
</body>
</html>

This file is save as "request.html". In this file post.php is called.




If we use the POST method then the URL of the browser is not append. You can see in
the following image.
PHP Tutorials By Vineet Kumar Saini




If we use the GET method then the URL of the browser is changed. You can see in the
following image.




Conclusion

So in this article you saw the differences between the GET and POST methods in PHP.

More Related Content

PPTX
Php.ppt
PPT
Php Presentation
PPTX
Html5 semantics
PPT
Java Script ppt
PPT
PHP - Introduction to PHP Forms
PPTX
Basic HTML
PPTX
Html tags
PPT
Introduction to Cascading Style Sheets (CSS)
Php.ppt
Php Presentation
Html5 semantics
Java Script ppt
PHP - Introduction to PHP Forms
Basic HTML
Html tags
Introduction to Cascading Style Sheets (CSS)

What's hot (20)

PDF
jQuery for beginners
PDF
PPTX
Basic Html Knowledge for students
PPT
CSS for Beginners
PPTX
HTML Semantic Elements
PPTX
PPTX
PPTX
Introduction to php
PPT
Introduction to PHP
PPTX
Html coding
PPT
Php forms
PPT
PHP POWERPOINT SLIDES
PDF
Flexbox and Grid Layout
PPTX
HTML (Web) basics for a beginner
PPT
Introduction to CSS
ODP
PDF
Introduction to HTML5
PPTX
HTML Semantic Tags
PPTX
jQuery for beginners
Basic Html Knowledge for students
CSS for Beginners
HTML Semantic Elements
Introduction to php
Introduction to PHP
Html coding
Php forms
PHP POWERPOINT SLIDES
Flexbox and Grid Layout
HTML (Web) basics for a beginner
Introduction to CSS
Introduction to HTML5
HTML Semantic Tags
Ad

Viewers also liked (20)

PDF
AT COMMAND SET FOR SENDING DATA VIA TCP USING SIM900
PDF
Getting Started with SainSmart SIM900 GPRS (Autosaved)
PDF
GSM GPRS SIM900A Modem
PDF
SQL Limit in PHP
PDF
CSS in HTML
PDF
Browser information in PHP
PDF
Programming in C
PDF
Pagination in PHP
PDF
MVC in PHP
PDF
2014 App Dev Confr. - iBeacons, BLE Beacons and Everything in Between.
PDF
About BLE server profile
PDF
Most usefull at commands
PPTX
Ble overview and_implementation
PDF
PDF
The Internet of Things: BLE / Beacons / iBeacons
PPT
Bluetooth low energy(ble) wireless technology
PDF
Gsm based campus display system project report
PDF
Practice exam php
PDF
PHP Technical Questions
PDF
Top 100 PHP Interview Questions and Answers
AT COMMAND SET FOR SENDING DATA VIA TCP USING SIM900
Getting Started with SainSmart SIM900 GPRS (Autosaved)
GSM GPRS SIM900A Modem
SQL Limit in PHP
CSS in HTML
Browser information in PHP
Programming in C
Pagination in PHP
MVC in PHP
2014 App Dev Confr. - iBeacons, BLE Beacons and Everything in Between.
About BLE server profile
Most usefull at commands
Ble overview and_implementation
The Internet of Things: BLE / Beacons / iBeacons
Bluetooth low energy(ble) wireless technology
Gsm based campus display system project report
Practice exam php
PHP Technical Questions
Top 100 PHP Interview Questions and Answers
Ad

Similar to GET and POST in PHP (20)

PDF
Making web forms using php
PPTX
A179178417_21_2025_PHP Get and Post.pptx
PPTX
5. Formshcfsjhfajkjsfjsjfjksafjsfjkjfhjsafjsajkgfjskafkjas.pptx
PDF
Introduction to php web programming - get and post
PPTX
Web Techniques like Cookies and Sessions
PDF
PHP-Part4
PPTX
Get and post methods in php - phpgurukul
PPT
Lecture7 form processing by okello erick
PDF
Web Development Course: PHP lecture 2
PDF
PHP Making Web Forms
PPTX
Form Handling using PHP
DOCX
Php forms and validations by naveen kumar veligeti
PPTX
WorkingwithFormsinPHPpptx__2024_10_17_19_07_07 2.pptx
PDF
Web app development_php_07
PDF
Form handling in php
PPTX
Unit - III.pptxbgffhjxfjdfjfgjnsnsnshdhsjsksjsjsjsjsjsjsjsjsldksk
PPTX
Unit - III.pptxbgffhjxfjdfjfgjnsnsnshdhsjsksjsjsjsjsjsjsjsjsldksk
PPT
Class 6 - PHP Web Programming
PPTX
forms.pptx
Making web forms using php
A179178417_21_2025_PHP Get and Post.pptx
5. Formshcfsjhfajkjsfjsjfjksafjsfjkjfhjsafjsajkgfjskafkjas.pptx
Introduction to php web programming - get and post
Web Techniques like Cookies and Sessions
PHP-Part4
Get and post methods in php - phpgurukul
Lecture7 form processing by okello erick
Web Development Course: PHP lecture 2
PHP Making Web Forms
Form Handling using PHP
Php forms and validations by naveen kumar veligeti
WorkingwithFormsinPHPpptx__2024_10_17_19_07_07 2.pptx
Web app development_php_07
Form handling in php
Unit - III.pptxbgffhjxfjdfjfgjnsnsnshdhsjsksjsjsjsjsjsjsjsjsldksk
Unit - III.pptxbgffhjxfjdfjfgjnsnsnshdhsjsksjsjsjsjsjsjsjsjsldksk
Class 6 - PHP Web Programming
forms.pptx

More from Vineet Kumar Saini (20)

PDF
Abstract Class and Interface in PHP
PDF
Add edit delete in Codeigniter in PHP
PDF
Introduction to Html
PDF
Computer Fundamentals
PDF
Country State City Dropdown in PHP
PDF
Stripe in php
PDF
Php Tutorials for Beginners
PDF
Install Drupal on Wamp Server
PDF
Joomla 2.5 Tutorial For Beginner PDF
PDF
Functions in PHP
PDF
Sorting arrays in PHP
PDF
Dropdown List in PHP
PDF
Update statement in PHP
PDF
Delete statement in PHP
PDF
Implode & Explode in PHP
PDF
Types of Error in PHP
PDF
Database connectivity in PHP
PDF
Arrays in PHP
PDF
Operators in PHP
PDF
Variables in PHP
Abstract Class and Interface in PHP
Add edit delete in Codeigniter in PHP
Introduction to Html
Computer Fundamentals
Country State City Dropdown in PHP
Stripe in php
Php Tutorials for Beginners
Install Drupal on Wamp Server
Joomla 2.5 Tutorial For Beginner PDF
Functions in PHP
Sorting arrays in PHP
Dropdown List in PHP
Update statement in PHP
Delete statement in PHP
Implode & Explode in PHP
Types of Error in PHP
Database connectivity in PHP
Arrays in PHP
Operators in PHP
Variables in PHP

Recently uploaded (20)

PDF
Basic Mud Logging Guide for educational purpose
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
01-Introduction-to-Information-Management.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Pre independence Education in Inndia.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Cell Structure & Organelles in detailed.
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Basic Mud Logging Guide for educational purpose
Module 4: Burden of Disease Tutorial Slides S2 2025
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Renaissance Architecture: A Journey from Faith to Humanism
Week 4 Term 3 Study Techniques revisited.pptx
01-Introduction-to-Information-Management.pdf
human mycosis Human fungal infections are called human mycosis..pptx
Supply Chain Operations Speaking Notes -ICLT Program
Pre independence Education in Inndia.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
Pharmacology of Heart Failure /Pharmacotherapy of CHF
2.FourierTransform-ShortQuestionswithAnswers.pdf
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
O7-L3 Supply Chain Operations - ICLT Program
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Cell Structure & Organelles in detailed.
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf

GET and POST in PHP

  • 1. PHP Tutorials By Vineet Kumar Saini $_GET and $_POST in PHP Introduction Using the GET and POST methods, the browser client can send data to the web server. In PHP the GET and POST methods are used to retrieve information from forms, such as user input. Get and Post are methods used to send data to the server. These methods are used for data handling in forms. Where each method varies a little in the way they work. GET Method In the GET method, we can also send data to the server. But when using the GET method we can't send the login details with a password because it is less secure (information sent from a form with the GET method is visible to everyone). We can say that the GET method is for getting something from the server; it doesn't mean that you cannot send a parameter to the server. The main points about the GET method are as follows:  The GET method is used to collect values in a form.  GET method is used when the URL is sent to the server.  GET method has limits on the amount of information to send because URL lengths are limited.  The Get method is used to retrieve web pages from the server.  The GET method is the default method for many browsers.  Data is sent as a part of the URL in 'name-value' pairs.  In the GET method page and the encoded information are separated by the question mark (?) sign.  In the GET method, the browser appends the data onto the URL.  The Get method is less secure because information sent from a form with the GET method is visible to everyone (it will be displayed in the browser's address bar) .  GET can't be used to send binary data, like images or word documents, to the server. Example First of all we create a PHP file which is called by the HTML page in later. <html> <body bgcolor="pink"> Welcome <?php echo $_GET ["Name"]; ?>.<br/> You are <?php echo $_GET ["Class"]; ?> Qualified !! </body> </html> The above file is to be saved with the name "get.php", which is called by the HTML page later. <html> <body bgcolor="pink"><table>
  • 2. PHP Tutorials By Vineet Kumar Saini <form action="get.php" method="get"> <tr><td>Name: <input type="text" name="Name" /></td></tr> <tr><td>Class : <input type="text" name="Class" /></td></tr> <input type="submit" " value="Submit"/> </form> </body> </html> This file is saved as "get.html". In this file get.php is called. Output You will put the URL in the web browser like as: http://localhost/FolderName/get.html. Now you will fill text like as name and class. When you click on the submit button then you will see your browser URL changed. You can see in the following image.
  • 3. PHP Tutorials By Vineet Kumar Saini POST Method In PHP $_POST variable is used to collect values from a form sent with method="post". In the POST method one can request as well as send some data to the server. The POST method is used when one can send a long enquiry form. Using the POST method the login details with password can be posted because it is secure (information sent from a form with the POST method is invisible to everyone). The main points about POST method are as follows:  The POST method is used to collect values from a form.  The POST method has no limits on the amount of information to send because URL lengths are unlimited.  The POST method is the not default method for many browsers.  In the POST method, the page and the encoded information are not separated by the question mark (?) sign.  In the POST method, the browser doesn't append the data onto the URL.  The POST method is secure because information sent from a form with the GET method is invisible to everyone.  The POST method can be used to send binary data, like images or Word documents, to the server.  In the POST method, the data is sent as standard input.  The POST method is slower than the GET method.  PHP provides the $_POST associative array to access all the information sent using the GET method. Example First of all we create a PHP file which is called by the HTML page later. <html> <body bgcolor="pink"> Welcome <?php echo $_POST ["Name"]; ?>.<br/> You are <?php echo $_POST ["Class"]; ?> Qualified !! </body> </html> The above file is saved with the "post.php" name, which is called by the HTML page later. <html> <body bgcolor="pink"> <table> <form action="post.php" method="post"> <tr><td>Name: <input type="text" name="Name" /></td></tr> <tr><td>Class : <input type="text" name="Class" /></td></tr> <input type="submit" " value="Submit"/> </form> </body> </html> This file is saved as "post.html". In this file post.php is called.
  • 4. PHP Tutorials By Vineet Kumar Saini Now you will fill text like as name and class. When you click on the submit button then you will see your browser URL is not changed. You can see in the following image. $_REQUEST Variable The $_REQUEST variable is also used to send data to the server. The $_REQUEST variable is a predefined variable in PHP. Which keeps the $_GET, $_POST and also $_Cookie variable. This variable is used to collect data of the form sent by the GET and POST methods. First of all we create a PHP file which is called by the HTML page later. <html> <body bgcolor="pink"> Welcome <?php echo $_REQUEST ["Name"]; ?>.<br/> You are <?php echo $_REQUEST ["Class"]; ?> Qualified !!
  • 5. PHP Tutorials By Vineet Kumar Saini </body> </html> The above file is saved with the "request.php" name, which is called by the HTML page later. <html> <body bgcolor="pink"> <table> <form action="request.php" method="post"> <tr><td>Name: <input type="text" name="Name" /></td></tr> <tr><td>Class : <input type="text" name="Class" /></td></tr> <input type="submit" " value="Submit"/> </form> </body> </html> This file is save as "request.html". In this file post.php is called. If we use the POST method then the URL of the browser is not append. You can see in the following image.
  • 6. PHP Tutorials By Vineet Kumar Saini If we use the GET method then the URL of the browser is changed. You can see in the following image. Conclusion So in this article you saw the differences between the GET and POST methods in PHP.