SlideShare uma empresa Scribd logo
1 de 6
Baixar para ler offline
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.

Mais conteúdo relacionado

Mais procurados (20)

Class 5 - PHP Strings
Class 5 - PHP StringsClass 5 - PHP Strings
Class 5 - PHP Strings
 
Hyperlinks in HTML
Hyperlinks in HTMLHyperlinks in HTML
Hyperlinks in HTML
 
Ajax ppt - 32 slides
Ajax ppt - 32 slidesAjax ppt - 32 slides
Ajax ppt - 32 slides
 
Data types in php
Data types in phpData types in php
Data types in php
 
Operators in PHP
Operators in PHPOperators in PHP
Operators in PHP
 
Php basics
Php basicsPhp basics
Php basics
 
Php forms
Php formsPhp forms
Php forms
 
Statements and Conditions in PHP
Statements and Conditions in PHPStatements and Conditions in PHP
Statements and Conditions in PHP
 
Java script errors &amp; exceptions handling
Java script  errors &amp; exceptions handlingJava script  errors &amp; exceptions handling
Java script errors &amp; exceptions handling
 
PHP - Introduction to PHP Forms
PHP - Introduction to PHP FormsPHP - Introduction to PHP Forms
PHP - Introduction to PHP Forms
 
Working with arrays in php
Working with arrays in phpWorking with arrays in php
Working with arrays in php
 
PHP Cookies and Sessions
PHP Cookies and SessionsPHP Cookies and Sessions
PHP Cookies and Sessions
 
Get method and post method
Get method and post methodGet method and post method
Get method and post method
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
 
Oops concepts in php
Oops concepts in phpOops concepts in php
Oops concepts in php
 
Javascript
JavascriptJavascript
Javascript
 
CSS
CSSCSS
CSS
 
PHP - Introduction to File Handling with PHP
PHP -  Introduction to  File Handling with PHPPHP -  Introduction to  File Handling with PHP
PHP - Introduction to File Handling with PHP
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScript
 
Arrays in PHP
Arrays in PHPArrays in PHP
Arrays in PHP
 

Destaque

AT COMMAND SET FOR SENDING DATA VIA TCP USING SIM900
AT COMMAND SET FOR SENDING DATA VIA TCP USING SIM900AT COMMAND SET FOR SENDING DATA VIA TCP USING SIM900
AT COMMAND SET FOR SENDING DATA VIA TCP USING SIM900Devrhoid Davis
 
Getting Started with SainSmart SIM900 GPRS (Autosaved)
Getting Started with SainSmart SIM900 GPRS (Autosaved)Getting Started with SainSmart SIM900 GPRS (Autosaved)
Getting Started with SainSmart SIM900 GPRS (Autosaved)Devrhoid Davis
 
GSM GPRS SIM900A Modem
GSM GPRS SIM900A ModemGSM GPRS SIM900A Modem
GSM GPRS SIM900A ModemRaghav Shetty
 
2014 App Dev Confr. - iBeacons, BLE Beacons and Everything in Between.
2014 App Dev Confr. - iBeacons, BLE Beacons and Everything in Between.2014 App Dev Confr. - iBeacons, BLE Beacons and Everything in Between.
2014 App Dev Confr. - iBeacons, BLE Beacons and Everything in Between.John Donohoe
 
About BLE server profile
About BLE server profile About BLE server profile
About BLE server profile Lin Steven
 
Ble overview and_implementation
Ble overview and_implementationBle overview and_implementation
Ble overview and_implementationStanley Chang
 
The Internet of Things: BLE / Beacons / iBeacons
The Internet of Things: BLE / Beacons / iBeaconsThe Internet of Things: BLE / Beacons / iBeacons
The Internet of Things: BLE / Beacons / iBeaconsVectorform
 
Bluetooth low energy(ble) wireless technology
Bluetooth low energy(ble) wireless technologyBluetooth low energy(ble) wireless technology
Bluetooth low energy(ble) wireless technologyLin Steven
 
Gsm based campus display system project report
Gsm based campus display system project reportGsm based campus display system project report
Gsm based campus display system project reportKashyap Shah
 
PHP Technical Questions
PHP Technical QuestionsPHP Technical Questions
PHP Technical QuestionsPankaj Jha
 
Top 100 PHP Interview Questions and Answers
Top 100 PHP Interview Questions and AnswersTop 100 PHP Interview Questions and Answers
Top 100 PHP Interview Questions and AnswersVineet Kumar Saini
 

Destaque (20)

AT COMMAND SET FOR SENDING DATA VIA TCP USING SIM900
AT COMMAND SET FOR SENDING DATA VIA TCP USING SIM900AT COMMAND SET FOR SENDING DATA VIA TCP USING SIM900
AT COMMAND SET FOR SENDING DATA VIA TCP USING SIM900
 
Getting Started with SainSmart SIM900 GPRS (Autosaved)
Getting Started with SainSmart SIM900 GPRS (Autosaved)Getting Started with SainSmart SIM900 GPRS (Autosaved)
Getting Started with SainSmart SIM900 GPRS (Autosaved)
 
GSM GPRS SIM900A Modem
GSM GPRS SIM900A ModemGSM GPRS SIM900A Modem
GSM GPRS SIM900A Modem
 
SQL Limit in PHP
SQL Limit in PHPSQL Limit in PHP
SQL Limit in PHP
 
CSS in HTML
CSS in HTMLCSS in HTML
CSS in HTML
 
Browser information in PHP
Browser information in PHPBrowser information in PHP
Browser information in PHP
 
Programming in C
Programming in CProgramming in C
Programming in C
 
Pagination in PHP
Pagination in PHPPagination in PHP
Pagination in PHP
 
MVC in PHP
MVC in PHPMVC in PHP
MVC in PHP
 
2014 App Dev Confr. - iBeacons, BLE Beacons and Everything in Between.
2014 App Dev Confr. - iBeacons, BLE Beacons and Everything in Between.2014 App Dev Confr. - iBeacons, BLE Beacons and Everything in Between.
2014 App Dev Confr. - iBeacons, BLE Beacons and Everything in Between.
 
About BLE server profile
About BLE server profile About BLE server profile
About BLE server profile
 
Most usefull at commands
Most usefull at commandsMost usefull at commands
Most usefull at commands
 
Ble overview and_implementation
Ble overview and_implementationBle overview and_implementation
Ble overview and_implementation
 
Sim900
Sim900Sim900
Sim900
 
The Internet of Things: BLE / Beacons / iBeacons
The Internet of Things: BLE / Beacons / iBeaconsThe Internet of Things: BLE / Beacons / iBeacons
The Internet of Things: BLE / Beacons / iBeacons
 
Bluetooth low energy(ble) wireless technology
Bluetooth low energy(ble) wireless technologyBluetooth low energy(ble) wireless technology
Bluetooth low energy(ble) wireless technology
 
Gsm based campus display system project report
Gsm based campus display system project reportGsm based campus display system project report
Gsm based campus display system project report
 
Practice exam php
Practice exam phpPractice exam php
Practice exam php
 
PHP Technical Questions
PHP Technical QuestionsPHP Technical Questions
PHP Technical Questions
 
Top 100 PHP Interview Questions and Answers
Top 100 PHP Interview Questions and AnswersTop 100 PHP Interview Questions and Answers
Top 100 PHP Interview Questions and Answers
 

Semelhante a GET and POST in PHP

Get and post methods in php - phpgurukul
Get and post methods in php  - phpgurukulGet and post methods in php  - phpgurukul
Get and post methods in php - phpgurukulPHPGurukul Blog
 
Lecture7 form processing by okello erick
Lecture7 form processing by okello erickLecture7 form processing by okello erick
Lecture7 form processing by okello erickokelloerick
 
Web Development Course: PHP lecture 2
Web Development Course: PHP lecture 2Web Development Course: PHP lecture 2
Web Development Course: PHP lecture 2Gheyath M. Othman
 
Php forms and validations by naveen kumar veligeti
Php forms and validations by naveen kumar veligetiPhp forms and validations by naveen kumar veligeti
Php forms and validations by naveen kumar veligetiNaveen Kumar Veligeti
 
Web app development_php_07
Web app development_php_07Web app development_php_07
Web app development_php_07Hassen Poreya
 
Form handling in php
Form handling in phpForm handling in php
Form handling in phpFahad Khan
 
Class 6 - PHP Web Programming
Class 6 - PHP Web ProgrammingClass 6 - PHP Web Programming
Class 6 - PHP Web ProgrammingAhmed Swilam
 
Web Application Development using PHP Chapter 5
Web Application Development using PHP Chapter 5Web Application Development using PHP Chapter 5
Web Application Development using PHP Chapter 5Mohd Harris Ahmad Jaal
 
Working with data.pptx
Working with data.pptxWorking with data.pptx
Working with data.pptxSherinRappai
 
Introduction to web development - HTML 5
Introduction to web development - HTML 5Introduction to web development - HTML 5
Introduction to web development - HTML 5Ayoub Ghozzi
 
Chapter 1.Web Techniques_Notes.pptx
Chapter 1.Web Techniques_Notes.pptxChapter 1.Web Techniques_Notes.pptx
Chapter 1.Web Techniques_Notes.pptxShitalGhotekar
 
PHP Forms PHP 05
PHP Forms PHP 05PHP Forms PHP 05
PHP Forms PHP 05Spy Seat
 

Semelhante a GET and POST in PHP (20)

Making web forms using php
Making web forms using phpMaking web forms using php
Making web forms using php
 
Introduction to php web programming - get and post
Introduction to php  web programming - get and postIntroduction to php  web programming - get and post
Introduction to php web programming - get and post
 
PHP-Part4
PHP-Part4PHP-Part4
PHP-Part4
 
Get and post methods in php - phpgurukul
Get and post methods in php  - phpgurukulGet and post methods in php  - phpgurukul
Get and post methods in php - phpgurukul
 
Lecture7 form processing by okello erick
Lecture7 form processing by okello erickLecture7 form processing by okello erick
Lecture7 form processing by okello erick
 
Web Development Course: PHP lecture 2
Web Development Course: PHP lecture 2Web Development Course: PHP lecture 2
Web Development Course: PHP lecture 2
 
PHP Making Web Forms
PHP Making Web FormsPHP Making Web Forms
PHP Making Web Forms
 
Php forms and validations by naveen kumar veligeti
Php forms and validations by naveen kumar veligetiPhp forms and validations by naveen kumar veligeti
Php forms and validations by naveen kumar veligeti
 
Web app development_php_07
Web app development_php_07Web app development_php_07
Web app development_php_07
 
Form handling in php
Form handling in phpForm handling in php
Form handling in php
 
Class 6 - PHP Web Programming
Class 6 - PHP Web ProgrammingClass 6 - PHP Web Programming
Class 6 - PHP Web Programming
 
forms.pptx
forms.pptxforms.pptx
forms.pptx
 
Sessions n cookies
Sessions n cookiesSessions n cookies
Sessions n cookies
 
Web Application Development using PHP Chapter 5
Web Application Development using PHP Chapter 5Web Application Development using PHP Chapter 5
Web Application Development using PHP Chapter 5
 
Working with data.pptx
Working with data.pptxWorking with data.pptx
Working with data.pptx
 
Introduction to web development - HTML 5
Introduction to web development - HTML 5Introduction to web development - HTML 5
Introduction to web development - HTML 5
 
Session and cookies ,get and post methods
Session and cookies ,get and post methodsSession and cookies ,get and post methods
Session and cookies ,get and post methods
 
Chapter 1.Web Techniques_Notes.pptx
Chapter 1.Web Techniques_Notes.pptxChapter 1.Web Techniques_Notes.pptx
Chapter 1.Web Techniques_Notes.pptx
 
Get and post methods
Get and post methodsGet and post methods
Get and post methods
 
PHP Forms PHP 05
PHP Forms PHP 05PHP Forms PHP 05
PHP Forms PHP 05
 

Mais de Vineet Kumar Saini (20)

Abstract Class and Interface in PHP
Abstract Class and Interface in PHPAbstract Class and Interface in PHP
Abstract Class and Interface in PHP
 
Add edit delete in Codeigniter in PHP
Add edit delete in Codeigniter in PHPAdd edit delete in Codeigniter in PHP
Add edit delete in Codeigniter in PHP
 
Introduction to Html
Introduction to HtmlIntroduction to Html
Introduction to Html
 
Computer Fundamentals
Computer FundamentalsComputer Fundamentals
Computer Fundamentals
 
Country State City Dropdown in PHP
Country State City Dropdown in PHPCountry State City Dropdown in PHP
Country State City Dropdown in PHP
 
Stripe in php
Stripe in phpStripe in php
Stripe in php
 
Php Tutorials for Beginners
Php Tutorials for BeginnersPhp Tutorials for Beginners
Php Tutorials for Beginners
 
Install Drupal on Wamp Server
Install Drupal on Wamp ServerInstall Drupal on Wamp Server
Install Drupal on Wamp Server
 
Joomla 2.5 Tutorial For Beginner PDF
Joomla 2.5 Tutorial For Beginner PDFJoomla 2.5 Tutorial For Beginner PDF
Joomla 2.5 Tutorial For Beginner PDF
 
Functions in PHP
Functions in PHPFunctions in PHP
Functions in PHP
 
Sorting arrays in PHP
Sorting arrays in PHPSorting arrays in PHP
Sorting arrays in PHP
 
Dropdown List in PHP
Dropdown List in PHPDropdown List in PHP
Dropdown List in PHP
 
Update statement in PHP
Update statement in PHPUpdate statement in PHP
Update statement in PHP
 
Delete statement in PHP
Delete statement in PHPDelete statement in PHP
Delete statement in PHP
 
Implode & Explode in PHP
Implode & Explode in PHPImplode & Explode in PHP
Implode & Explode in PHP
 
Types of Error in PHP
Types of Error in PHPTypes of Error in PHP
Types of Error in PHP
 
Database connectivity in PHP
Database connectivity in PHPDatabase connectivity in PHP
Database connectivity in PHP
 
Arrays in PHP
Arrays in PHPArrays in PHP
Arrays in PHP
 
Variables in PHP
Variables in PHPVariables in PHP
Variables in PHP
 
Print function in PHP
Print function in PHPPrint function in PHP
Print function in PHP
 

Último

Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 

Último (20)

Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 

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.