PHP Example HTML Javascript jQuery Ajax CSS Java MORE

Difference between GET and POST PHP

In PHP there are two ways to send information to server.

These are GET and POST. $_GET and $_POST both are super global variable.

The variable which is always accessible is called as super global variable.

Difference

$_GET :

  1. $_GET is super global variable.
  2. Data send in GET is visible in URL.
  3. Not preferable for send sensitive data.
  4. Limitation of send data.(About 2000 character)
  5. In GET you send information to server in two way :
    1. Through URL
    2. Through from

Through URL

Example

<!DOCTYPE html>
<html>
<body>
<a href=“http://www.example.com/action.php?name=john&age=24">Send</a>
</body>
</html>

Through From

Example

<!DOCTYPE html>
<html>
<body>
<form action="action_page.php" method="get">
First name:<br>
<input type="text" name="firstname">
<br>
Last name:<br>
<input type="text" name="lastname">
<br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>

In action_page.php we gather the information using $_GET super global variable.

$_POST

  1. $_GET is super global variable.
  2. Data send in POST is not visible in URL.
  3. Preferable for send sensitive data.
  4. No limitation for send data.
  5. In POST you send information to server in one way that is form.

Example

<!DOCTYPE html>
<html>
<body>
<form action="action_page.php" method="post">
First name:<br>
<input type="text" name="firstname">
<br>
Last name:<br>
<input type="text" name="lastname">
<br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>

In action_page.php we gather the information using $_POST super global variable.