Skip to Content
Learn
HTML Form Handling in PHP
Request Superglobals

Since PHP was built with web development as a primary use case, it has functionality to ease processing of HTML requests. When the front end client makes a request to a backend PHP server, several superglobals related to the request are available to the PHP script. Superglobals are automatic global variables which are available in all scopes throughout a script.

The list of superglobals in PHP includes the following:

  • $GLOBALS
  • $_SERVER
  • $_GET
  • $_POST
  • $_FILES
  • $_COOKIE
  • $_SESSION
  • $_REQUEST
  • $_ENV

For this lesson, we are focusing on three of these:

  • $_GET - this contains an associative array of variables passed to the current script using query parameters in the URL
  • $_POST - this contains an associative array of variables passed to the current script using a form submitted using the “POST” method
  • $_REQUEST - this contains the contents of $_GET, $_POST, and $_COOKIE

Instructions

1.

In the code, we’ve set up two HTML forms, one using the “GET” method and one using the “POST” method.

Print the values of the $_REQUEST, $_GET, and $_POST superglobals after their corresponding text in the HTML using the built-in print_r function.

2.

Try typing some words into each of the forms and submitting them to examine the behavior of these superglobals. Use the “reset” button to reset the form.

When does the URL in the demo browser change?

Folder Icon

Take this course for free

Already have an account?