The GET Method

If you can use GET method at that time use $_GET global variable.

http://www.example.com/action.php?name=abc&age=24

$_GET can also collect information/data sent in the URL.

Try out following example by putting the source code in demo.php script.

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Example of PHP GET method</title>
</head>
<body>
<?php
if(isset($_GET["name"])){
    echo "Name is " . $_GET["name"];
}
?>
<form method="get" action="">
    <label for="name">Name:</label>
    <input type="text" name="name" id="name">
    <input type="submit" value="Submit">
</form>
</body>
</html>

The POST Method

POST method to you can pass data/information securly in action page.

The PHP provides $_POST associative array to access all the sent data/information using POST method.

Try out following example by putting the source code in demo.php script.

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Example of PHP POST method</title>
</head>
<body>
<?php
if(isset($_POST["name"])){
    echo "Name is " . $_POST["name"];
}
?>
<form method="post" action="">
    <label for="name">Name:</label>
    <input type="text" name="name" id="name">
    <input type="submit" value="Submit">
</form>
</body>
</html>

The $_REQUEST Variable

PHP provides another superglobal variable $_REQUEST that contains the values of both the $_GET and $_POST superglobal variable.

Try out following example by putting the source code in demo.php script.

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Example of PHP $_REQUEST variable</title>
</head>
<body>
<?php
if(isset($_REQUEST["name"])){
    echo "Name is " . $_REQUEST["name"];
}
?>
<form method="post" action="">
    <label for="name">Name:</label>
    <input type="text" name="name" id="name">
    <input type="submit" value="Submit">
</form>
</body>
</html>