There are two ways the browser client can send information to the web server.
- 1. GET method
- 2. POST method
There are two ways the browser client can send information to the web server.
This method instructs the browser to send the encoded information (the name/value pairs) through the URL parameter by appending it to the page request. The browser implement this method by concatenating the question mark character (?) to the end of the page request since it specifies where the query string (name/values pairs) starts from, and all the form data is visible to everyone as it is displayed in the browser address bar.
File: example_get_form.html
<form action="get_action_page.php" method="post">
<div class="form-group">
<label for="username">Username:</label>
<input type="text" name="username" class="form-control" id="username" />
</div>
<div class="form-group">/span>
<label for="pwd">Password:</label>
<input type="password" name="password" class="form-control" id="pwd" />
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
File: get_action_page.php
<?php
echo "Username : " . $_GET['username'];
echo "Password : " . $_GET['password'];
?>
This method sends information via HTTP header. All name/value pairs sent through this method is invisible to anyone else since all the information are embedded within the body of the HTTP request.
When you submit a form to a server through the POST method, PHP provides a superglobal variable called $_POST. The $_POST variable is used by PHP to create an associative array with an access key ($_POST['name as key']). The key is created automatically by PHP when the form is submitted. PHP uses the form field element name attribute (name="unique-name-here") to create the key.
File: example_post_form.html
<form action="post_action_page.php" method="post">
<div class="form-group">
<label for="username">Username:</label>
<input type="text" name="username" class="form-control" id="username" />
</div>
<div class="form-group">/span>
<label for="pwd">Password:</label>
<input type="password" name="password" class="form-control" id="pwd" />
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
File: post_action_page.php
<?php
echo "Username : " . $_POST['username'];
echo "Password : " . $_POST['password'];
?>