Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

186
Vistas
Different ways to use local variables from HTML / Javascript in PHP

Recently I have been doing a lot of work in PHP and I have become familiar with how it works. I stand by what I have said before; That every problem has an endless amount of solutions. So that is what I am after, solutions that solve the same problem.

In this case, I want variables/references to values from localstorage:

localStorage.setItem("user", "bananaflakes55");
localStorage.getItem("user");

and directly include them in PHP files. Now I have found out that using echo have a variety of uses, for example:

echo '<script type="text/javascript"> window.location.replace("' . $refclinklogin . '"); </script>';

Granted that the value there are on serverside -> client side. In this case I want similar solutions that necessarily wont require me to create a GET or POST, with HTML elements like forms, that connect these.

To sum up, I want solutions that can bring values from local and session storage, to PHP. Bring forth some funky ideas, if possible. From what I have read it is a tricky one.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Even if i understand what you want, process sould be running from PHP to client rather than the reverse.

With this in mind, a light solution can be something like that :

window.addEventListener("load", function() {
    let request = new XMLHttpRequest();

    request.open("POST", 'localStorageToSession.php', true);

    request.onload = function () {
        let saveResponse = request.responseText;
        // if you want a callback or use some script return

    }
    let data = "jsonLocalStorage=" + JSON.stringify(window.localStorage);

    request.send(data);
}) ;

Once the page is loaded, send all localStorage parsed in json to a PHP treatment (here called localStorageToSession.php). So you can convert localstorage as $_SESSION. Something like that :

$_SESSION['jsLocalStorage'] = json_decode($_POST['jsonLocalStorage'], true) ;

Then you can use $_SESSION['jsLocalStorage'] in your backend treatments. Don't forget to add session_start() on all your files. You can save the xml request in a function and call once localStorage is updated).

Even if that solution works, i don't recommand it if you have to deal with safety informations like passwords or user special access.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda