Clear variables in url in the best way!

0

What other alternatives do I have besides headerremove to clean the url of my document when loading / reloading a page and get variables in special cases by get? I like the idea of sending variables by url in the backend and cleaning them in the same way after obtaining them, I do not know if it's a good practice!

    
asked by matteo 07.12.2017 в 16:57
source

2 answers

1

In PHP you could do it in the following way:

<?php
session_start();

if ( !empty( $_GET ) ) {

   // En el caso que este NO este vacío el $_GET
   // lo pasamos a una variable de sesión
   // y limpiamos la URL sin los parametros $_GET con el header(..)

   $_SESSION[ 'variable_get' ] = $_GET;
   header('Location: http://ejemplo.com');
}

if ( !empty( $_SESSION[ 'variable_get' ] ) ) {

   // En el caso que este vacío el $_GET 
   // y NO este vacío la variable de sesión variable_get
   // lo pasamos de vuelta a la variable $_GET
   // y reseteamos la variable de sesión variable_get

   $_GET = $_SESSION[ 'variable_get' ];
   $_SESSION[ 'variable_get' ] = null;
}
else {
   // Tratar error de no haber obtenido nada
   // header(..);
   // exit;
}    

// A partir de aquí puedes usar la variable $_GET con la URL limpia
    
answered by 07.12.2017 в 17:31
1

It is not a good practice, since by doing this the "browsing and user experience, as well as its history" is affected.

Why ?, this is because many people use the buttons "back and forth" of the browser and when you reload, when you give "back" reload the same page that goes with your variables get and your script returns to reload the site.

This causes the user to "get stuck" on the same page, without mentioning that your server must serve the site once more, that it increases the load on it and perhaps save the variables in session, which increases your use of memory.

I recommend in that case, send your variables by POST so that they are hidden and people can not see them in your url.

GET variables are intended for navigation and "request for information" That is why they are named "get".

Once, I saw a place where they had a general iframe, with the entire site embedded. This made the url that the user observed, was www.-urldelsitio-.com and everything else, was handled in the iframe so the get variables were always hidden.

That's one of many ways to hide your url, but I'll go back to the previous point. I think it's a good application, it does not hide its URLs, it can even be friendly since they are intended for navigation.

Good luck friend.

    
answered by 07.12.2017 в 18:13