Get INPUT_GET from friendly url

0

Hello, my system has two panels. One of the Admin without any optimization in SEO, another of the user, where he can post articles and more. It turns out that I use a query to fetch the folder and return the requested file through the url.

It turns out that my front system is optimized, so the termination of .php files has been removed for SEO. Making the URL below unusable

Example:

mysite.com/user/dashboard.php?get=artigos/create

Note that dashboard.php makes the requisition for the articles folder and the create file inside it, but returns 404. Now suppose I change "?" by & and remove the .php from the URL the file is returned correctly. Staying like this:

mysite.com/user/dashboard&get=artigos/create

This is not recommended, so how to proceed? Thanks for the help.

About the script that removes the .php is a general function, so there is no folder checking or anything like that.

    
asked by anonymous 25.05.2016 / 14:59

1 answer

0

If you only have 1 parameter to grab you can do:

meusite.com/usuario/dashboard&get=artigos/criar :

$param = explode('&', $url); // array('meusite.com/usuario/dashboard', get=artigos/criar)
$param = explode('=', $param[1])[1]; // artigos/criar

But attention can have several parameters:

EX: meusite.com/usuario/dashboard&get=artigos/criar&get2=miguel :

$params = explode('&', $url); // array('meusite.com/usuario/dashboard', 'get=artigos/criar', 'get2=miguel')
$gets = array();
for($i = 1; $i < count($params); $i++) { // atenção que não precisamos do index 0 do array params
    $param = explode('=', $params[$i]);
    $gets[$param[0]] = $param[1];
}
// $gets = array('get' => 'artigos/criar', 'get2' => 'miguel');
    
25.05.2016 / 15:18