我可以使用php从localstorage获取数据吗?
问题描述:
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 on the client. The only way is to read the LocalStorage via JavaScript, and send the result to your server via ajax.
答
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.