Can I get data from localstorage using php if yes then tell me how in localstorage data set like this
<script>
var i=0;
function inc()
{
i+=1;
localStorage.setItem("qnum", i);
}
</script>
Can I get data from localstorage using php if yes then tell me how in localstorage data set like this
<script>
var i=0;
function inc()
{
i+=1;
localStorage.setItem("qnum", i);
}
</script>
No, you can't. PHP runs on your server, the localStorage
is only available in the browser of the client.
The only way is to read the localStorage
via JavaScript, and send the result to your server via ajax.
I tried with this code and it worked fine.
$Data = "<script>document.write(localStorage.getItem('key'));</script>";
print_r($Data);
localStorage
is something that is kept on the client side. There is no data transmitted to the server side.
You can only get the data with JavaScript and you could sent it to the server side with Ajax.
Another explanation goes like this: Your browser does not understand php, only javascript (along with html & css). Therefore, you need to read and set LocalStorage with Javascript and send it to a server, like Markus says.