What is $_GET['path']?

Asked

Viewed 523 times

1

I wonder what it means when someone uses it $_GET['path']? What would be the path? I thought the $_GET would only receive information from the URL.

public function get_url_data () {

    // Verifica se o parâmetro path foi enviado
    if ( isset( $_GET['path'] ) ) {

    // Captura o valor de $_GET['path']
    $path = $_GET['path'];

    // Limpa os dados
                        $path = rtrim($path, '/');
                        $path = filter_var($path, FILTER_SANITIZE_URL);

    // Cria um array de parâmetros
    $path = explode('/', $path);

    // Configura as propriedades
    $this->controlador  = chk_array( $path, 0 );
    $this->controlador .= '-controller';
    $this->acao         = chk_array( $path, 1 );

    // Configura os parâmetros
    if ( chk_array( $path, 2 ) ) {
    unset( $path[0] );
    unset( $path[1] );

    // Os parâmetros sempre virão após a ação
    $this->parametros = array_values( $path );
    }Fim if

If possible state what is path.

  • 1

    $_GET is different from get[''] !!! maybe this get be another thing array

  • As far as I know this doesn’t exist, maybe it’s an array created in your code called $get which contains the element path. What exists is $_GET['parametro']

  • 1

    sol25lua, put the code where it is. Without the context it is impossible to say. You should have noticed this in your other questions, which you only answered when you posted the code. Please pay more attention when asking here and read the guide to [Ask].

  • All right I’m sorry I’ll post in full, I’ll edit the question

  • 1

    @sol25lua need not apologize for anything stay quiet ... Slowly getting the hang of it ...

  • Yes, the $_GET takes information passed to the url itself. $_GET['path'] will take the value of a parameter called path present in the URL, if this parameter exists.

  • 1

    Because I amaze him with the path? Nothing complicated, you see: http://dominio.com?nome=sol25lua OR http://dominio.com?path=sol25lua recovering the value $_GET['nome'] OR $_GET['path'] both return sol25lua

  • The $_GET method is used to receive variables through the URL (Link that inserts in the browser), surely you have seen on some websites a link this way www.exemplo.com/index.php?path=sol25lua . The point of ? is the way to declare that the following are variables. After ? we can start declaring the variables. in this example we are defining the variable path with the value sol25lua

  • I get it, but if there’s more than one parameter in the URL, like this: http://domain.com?nomen=sol25lua? city=Curitiba to recover the value of $_GET['path'] what would be the result? sol25luacuritiba?

  • I don’t understand why every time a newbie shows up, who still doesn’t have a full understanding of Stark’s workings, they shoot to give him negative points. It should be the other way around to stimulate learning so that he becomes a member of this community and in the future help! + 1 @sol25lua next time only post formatted question!

  • If the url has more than one parameter you can access the values by the name given in the url, in your example above you would access $_GET['name'] would have the sol25lua value and $_GET['city'] would have the Curitiba value. $_GET and $_POST are global php scope variables. So they can be accessed from any part of the script.

Show 6 more comments

2 answers

5


The variable $_GET is a super-global used to take values from querystring.

Querystring, it would be anything that comes after the ? in the URL, example:

http://site.com/pagina?foo=bar&baz=foobar

They could be caught like this:

echo $_GET['foo']; //Exibe bar
echo $_GET['baz']; //Exibe foobar

And most likely $_GET['path'] is used by a .htaccess (or another system that uses mod_rewrite, like Nginx or lighttpd) to rewrite the URL, something like:

If it’s . htaccess (apache):

RewriteEngine On
RewriteRule ^(.*)$ rotas.php?path=$1 [L,QSA]

The (.*) takes the URL that is typed and rewrites passing with parameter to path=<rota>, the user sees something as:

http://site/foo/bar/baz

But in the back-end it runs:

http://site/rotas.php?path=foo/bar/baz

What allows you to create "friendly URL", most likely you are using this MVC framework:

That was created by Luiz to show an example of how to implement MVC with HTTP routes.

  • 1

    Thank you William excellent explanation.

0

In php $_GET serves to get parameters from the URL.

For example if you request a page like http://meusite.com?path=servicos

$_GET['path'] would return the 'services' string'

Browser other questions tagged

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