Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

185
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda