PHP in Browser Write, Read and Update .txt, Locally [closed]

0

In the client browser! Locally ...

How can I create and save to a local .txt file on the client machine the value of two String variables.

This script will be logged in and every time the login is done this update will be updated "overwritten" locally on the client machine passing updated values of these variables.

And then at another point in the script, read what is in this .txt file "the value of the two variables entered and updated earlier" and compare each of these values with two other variables in my script.

How can I perform this process?

.TXT

$strGuarda01
$strGuarda02

$strCompara01 == $strGuarda01
$strCompara02 == $strGuarda02
    
asked by anonymous 08.08.2017 / 19:18

2 answers

1

I'll try to explain it over the top. I hope you understand:

To Save data:

<script>
    localStorage.setItem('strGuarda01', '<?php echo $strGuarda01;?>');  
    localStorage.setItem('strGuarda02', '$strGuarda02');
</script>

To be able to retrieve this data you can send it to php as follows:

<script>
    var strGuarda01 = localStorage.getItem('strGuarda01'), strGuarda02= localStorage.getItem('strGuarda02');
    $.POST('login.php', {'strGuarda01':strGuarda01,'strGuarda02':strGuarda02}, function(data){
      ...
    }
</script>

And retrieve it on the .php page:

<?php
    $strGuarda01 = $_POST['strGuarda01'];
    $strGuarda01= $_POST['strGuarda02'];
    ...
?>

And to update:

<script>
    localStorage.clear();
    localStorage.setItem('strGuarda01', '<?php echo $strGuarda01;?>');  
    localStorage.setItem('strGuarda02', '$strGuarda02');
</script>

localStorage

The localStorage saves data on the visitor's computer, which is linked to (and only accessible by) your domain.

This tutorial might help you: link

    
08.08.2017 / 20:05
4

I think is not possible , because your PHP code is on a server outside the directory where you want to make the file modifications, so the browser can not make the change.

    
08.08.2017 / 19:27