URL and request parameters. Post - What method is used to transmit an http request in a form and without a form? How to make http requests
HTTP (Hyper Text Transport Protocol) is the very language in which browsers “talk” to web servers, the most important Internet protocol...
Types of requests
Requests can be divided into two types:
- GET;
- POST.
GET used when typing a site address in the browser line or follow the link. POST serves to submit forms, for example, when registering on a website or publishing a comment on an article. To submit a form, you usually need to click the “Submit” button or something similar:
For simplicity understanding the difference can be represented as follows:
- GET used for reading websites (we read the Internet);
- POST serves for publication information on websites (we write Internet)
URL and request parameters
In both cases it is required URL(Uniform Resource Locator) of the requested document.
URL - this is the address pages on the Internet. As a rule, it looks like this:
http://<хост>/<путь>
For example:
http://www.example.ru/about.php
Or this, if you need to pass parameters to the script:
http://<хост>/<путь>?<параметры>
Where<параметры>is a set of pairs of the form:
<имя>=<значение>
separated by symbol &
.
Example:
http://www.example.ru/news.php?id=100&show_comments=yes
You may experience question: For what transfer to script parameters? Dynamic page(aka script), unlike static, can produce various information. For example, a news feed script displays either a list of latest news announcements or the entire text of a specific article. The script understands what exactly the user wants to see based on the parameters passed to it.
It could work like this. Getting a list of the latest news: http://www.example.ru/news.php(URL without parameters). Receipt full text news article: http://www.example.ru/news.php ?id=1 (The URL includes the news number as a parameter).
Handling URL Parameters
And now we will write a script for this very news feed. She will have two modes:
We will have three news in total:
- “They will answer for quality. They have started to control food products in a new way”;
- “Warsaw does not disclose the list of possible measures against Minsk”;
- "Pavel Astakhov intends to seek the resignation of a number of officials in Udmurtia"
Now it’s important for us to learn how to process parameters passed via URL. So, create a news.php file:
"; echo "
"; echo "- "; for ($i = 0; $i< count($news); $i++)
{
echo "
- "; echo ""; echo $news[$i]; echo ""; echo " "; echo "