codescracker


php

PHP GET and POST



« Previous Tutorial Next Tutorial »


There are two ways available in PHP, that the browser client can send the information to the web server, which are:

Before, the browser sends the information to the web server, first it encodes using a scheme called URL encoding like this:

name1=value1&name2=value2&name3=value3

PHP GET Method

PHP GET method sends the encoded user information appended to the page request. The page and the encoded information are separated by the question mark (?) character. Here is an example:

PHP Code:
http://www.codescracker.com/form_submit.php?name1=value1&name2=value2

PHP GET Method Example

Here is an example, uses GET method to submit a form filled and submitted by a user in PHP:

<?php
  if( $_GET["name"] || $_GET["age"] )
  {
     echo "Welcome ". $_GET['name']. "<br />";
     echo "You are ". $_GET['age']. " years old.";
     exit();
  }
?>
<html>
<body>
  <form action="<?php $_PHP_SELF ?>" method="GET">
  Name: <input type="text" name="name" />
  Age: <input type="text" name="age" />
  <input type="submit" />
  </form>
</body>
</html>

PHP POST Method

The POST method transfers information via HTTP headers.

PHP POST Method Example

Here is an example, uses POST method to submit a form filled and submitted by a user in PHP:

<?php
  if( $_POST["name"] || $_POST["age"] )
  {
     echo "Welcome ". $_POST['name']. "<br />";
     echo "You are ". $_POST['age']. " years old.";
     exit();
  }
?>
<html>
<body>
  <form action="<?php $_PHP_SELF ?>" method="POST">

  Name: <input type="text" name="name" />
  Age: <input type="text" name="age" />

  <input type="submit" />
  </form>
</body>
</html>

« Previous Tutorial Next Tutorial »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test