Get INPUT_GET of friendly url

Asked

Viewed 171 times

0

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

It turns out my front system is optimized, so . php file terminations have been removed for SEO. Making the URL below unusable

Example:

meusite.com/user/Dashboard.php? get=articles/create

note that Dashboard.php does the request of the articles folder and the file create within it, but returns 404. Now let’s assume that I change "?" by & and remove . php from the URL the file is returned correctly. Thus:

meusite.com/usuario/dashboard&get=articles/create

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

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

  • it’s not better this way: meusite.com/usuario/dashboard?get=artigos/criar or meusite.com/usuario/dashboard/artigos/criar ?

  • This way it does not take the query, because the absence of the . php in the URL

  • You spoke url friendly, assume you would use . htaccess, if using . htaccess is possible.

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 beware that it 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');
  • Miguel, I like your solution, just a question. Speaking of security, there is some fault for hacking the url meusite.com/user/dashboard&get=articles/creat&get 2=miguel , hugs

  • Not if you do the necessary checks, which are exactly the same as you do, or should do, with the conventional method $_GET

  • For example: If you are waiting for a parameter called get and another one called get2. Should always if(isset($_GET['get']) && isset($_GET['get2'])) { .. tudo ok... else { .. não está tudo ok .. }

  • Valeu Miguel, in this system PDO use with all possible checks on safety.

  • No. PDO decreases the probabilities only that, the checks should always be made before any operation in the database

  • Or even if you’re not going to operate in the comic book but go do something else in your program that depends on it

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.