Answer the question
In order to leave comments, you need to log in
How to implement cnc in php like in wordpress or opencart so that urls are taken from the mysql database?
Hello, please tell me how to make a cnc in php so that the names are taken from the database, as, for example, done in opencart or in wordpress
Now my links work according to the get parameter id and look like this page.php? id=1 there is also such a link class.php ?id=1 how to do like this
page?id=1 turn into a link like this /razdel1/razdel2 and link class.php?id=1 turn into a link like this /razdel
/ Basically, all transformations with links are carried out in .htaccess, but this option does not suit me. I need all links to be taken from the database
and compared with each other .
For example
page.php?id=1 => razdel1/razdel2
page.php?id=2 => section3/section4
class.php?id=1 => /test/
class.php?id=2 => /test2/
How to do this ? Please write an example in php pdo Thank you
Answer the question
In order to leave comments, you need to log in
There is no way to do this without proxying or mod_rewrite. Requests are processed primarily by the web server, and if it is not told that all requests should be proxied to index.php, it will try to open such a path. And then, after proxying, just in PHP, you take the URL from the HTTP request, search in the database or manually register, compare and do what you need, depending on the page found.
$db = new PDO($dsn, $user, $password);
$sth = $db->prepare('SELECT * FROM routes WHERE route = :route LIMIT 1');
$sth->execute([ ':route' => $_SERVER['REQUEST_URI'] ]);
$result = $sth->fetch(PDO::FETCH_ASSOC);
if (!$result) {
echo "Not found!\n";
die();
}
$routeId = $result['id'];
// ваша логика по обработке запроса или отображения страницы
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question