R
R
Ruslan Samara2018-09-26 12:50:02
Web development
Ruslan Samara, 2018-09-26 12:50:02

How to work with URI requests in PHP? How to properly configure routing?

I just started learning back-end, started with PHP, so don't kick me.
Suppose there is a page on the site https://site.ru/spb/post?id=23
So I read various articles about routing in php, and did not understand how they usually go to pages such as spb, Let's say this is the section that is intended for a certain city and there are some posts with id. How the transition to the SPB page is carried out if there are a lot of such cities, you don’t need a code, but explain to me by what methods this can be done.
The first option, as I understand it, is a GET request in the form, it will look like https://site.ru/?city=spb/post?id=23, you can remove extra characters in it. thus there will be a line like https://site.ru/spb/post?id=23.
The second option, I suspect it is possible to implement the POST method, when submit submit will send to the page that exists physically - spb.php then post.php where there will also be links to posts and again work with GET requests to display the pages.
Are there any other options for going to pages that do not physically exist without using GET requests. I ask you not to write crooked options that are not used by web studios.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Stalker_RED, 2018-09-26
@lkmrus

it will look like https://site.ru/?city=spb/post?id=23

Of course, you can write any heresy in the address bar of the browser, but then the server part will have to be invented, well, so that it can parse this tricky line of yours.
In order not to reinvent it for each project, the standards were re-invented.
https://tools.ietf.org/html/rfc3986
And if you need to pass two parameters, then it will look like this:
on submit, submit will send to the page that exists physically - spb.php then post.php
Of course you can do it, but why? Do you really want to create physically existing pages for each city? I have more than 10 thousand of them in the current project, for example. I'd be tempted to create.
You can start here: How do large sites store their pages?

D
Dmitry Arushanov, 2018-09-26
@daruwanov

Read about .httaccess and mod_rewrite

N
Nikita Ermilichev, 2018-09-26
@Masas

As a rule, frameworks and CMS already have ready-made mechanisms. For a general understanding, I recommend looking at this article
maxsite.org/page/routing
(you don’t have to delve into everything, just understand the mod_rewrite module and what to do with it)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question