You are on page 1of 3

Chapter 1.

Web Techniques
1.3.1. Methods
There are two HTTP methods that a client can use to pass form data to the server: GET and
POST.
The method that a particular form uses is specified with the method attribute to the form tag.
Methods are case-insensitive in the HTML.
The most visible difference between GET and POST is the URL line.
GET POST
A GET request encodes the form A POST request passes the form parameters in the
parameters in the URL, in what is called a body of the HTTP request, leaving the URL
query string. URL such as untouched. URL such as
http://localhost/SemII/chunk.php?word=H http://localhost/SemII/chunk.php
ello+how+are+you&length=3&button=Ma
ke+Chunk
Form's parameters are encoded in the Bookmark cannot be done with POST requests.
URL with a GET request, users can
bookmark GET queries.

GET requests are idempotent i.e web POST requests are not idempotent means that
browsers can cache the response pages for web browser page cannot be cached, and the
GET requests, because the response page server is re-contacted every time the page is
doesn't change regardless of how many displayed.
times the page is loaded
GET requests should be used where the POST requests should be used for queries whose
response page is never going to change - response pages may change over time—for
for example, queries such as splitting a example, displaying the contents of a shopping
word into smaller chunks or multiplying cart or the current messages in a bulletin board.
numbers,

The type of method that was used to request a PHP page is available through
$_SERVER['REQUEST_METHOD']. For example:
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
// handle a GET request
}
else {
die("You may only GET this page.");
}

1.3.2. Parameters
Use the $_POST, $_GET, and $_FILES arrays to access form parameters from your PHP code.
The keys are the parameter names in HTML form, and the values are the values of those
parameters.
Example:
<html>
<form action="chunk.php" method="POST">
Enter the word: <input type="text" name=word><br>
How long should be the chunk: <input type="text"
name=length><br>
<input type="submit" name=button value="Make Chunk">
</form>
</html>

<html>
<head>
<title>
chunk words
</title> </head>
<body>
<?php
print_r($_GET);// Global get array
$word=$_GET['word'];
$length=$_GET['length'];
$no_of_chunks=ceil(strlen($word)/$length);
echo $no_of_chunks;
for ($i=0; $i < $no_of_chunks; $i++) {
$chunk = substr($word, $i*3, 3);
echo "<br>".($i+1) .":".$chunk."<br>";
}
?>
</body>
</html>

You might also like