Your SlideShare is downloading. ×
  • Like
GET and POST in PHP
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

GET and POST in PHP

  • 3,967 views
Published

 

Published in Education , Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
No Downloads

Views

Total Views
3,967
On SlideShare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
133
Comments
1
Likes
2

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. PHP Tutorials By Vineet Kumar Saini $_GET and $_POST in PHPIntroductionUsing the GET and POST methods, the browser client can send data to the web server. InPHP the GET and POST methods are used to retrieve information from forms, such as userinput. Get and Post are methods used to send data to the server. These methods are usedfor data handling in forms. Where each method varies a little in the way they work.GET MethodIn the GET method, we can also send data to the server. But when using the GET methodwe cant send the login details with a password because it is less secure (information sentfrom a form with the GET method is visible to everyone). We can say that the GET methodis for getting something from the server; it doesnt mean that you cannot send a parameterto 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 browsers address bar) .  GET cant be used to send binary data, like images or word documents, to the server.ExampleFirst 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 pagelater.<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.OutputYou 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 youwill see your browser URL changed. You can see in the following image.
  • 3. PHP Tutorials By Vineet Kumar SainiPOST MethodIn PHP $_POST variable is used to collect values from a form sent with method="post". Inthe POST method one can request as well as send some data to the server. The POSTmethod is used when one can send a long enquiry form. Using the POST method the logindetails with password can be posted because it is secure (information sent from a form withthe 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 doesnt 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.ExampleFirst 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 SainiNow you will fill text like as name and class. When you click on the submit button then youwill see your browser URL is not changed. You can see in the following image.$_REQUEST VariableThe $_REQUEST variable is also used to send data to the server. The $_REQUEST variable isa 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 pagelater.<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 inthe following image.
  • 6. PHP Tutorials By Vineet Kumar SainiIf we use the GET method then the URL of the browser is changed. You can see in thefollowing image.ConclusionSo in this article you saw the differences between the GET and POST methods in PHP.