I want to store the contents of local storage in a PHP variable without having to use a POST. I found this way, but it returns a string whose length is equal to the length of the entire script and the value is equal to the value stored in local storage. It is not used to make subsequent comparisons of the stored value.
Example:
$status = "<script>document.write(localStorage.getItem('click_on_menu'))</script>";
(local storage contains "ok")
var_dump($status); -> string(71)"ok"
when you do a comparison
strcmp($status,"ok")
returns that they are not equal (-1) because string length of the variable is 71
If I cast it to an integer and handle it with numbers:
$status =(int) "<script>document.write(localStorage.getItem('click_on_menu'))</script>"; (local storage contains 1)
I have also tried with settype, intval with the same result
It throws me the following
var_dump($status); -> int(0)
and does not read what is actually stored.
Any solution for this situation? Thanks for your time