dqfxao2898
2017-05-30 12:14
浏览 467

我可以使用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>
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • drelgkxl93433 2017-05-30 12:15
    已采纳

    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.

    已采纳该答案
    打赏 评论
  • dou12352 2017-05-30 12:16

    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.

    打赏 评论
  • dongtuoleng8624 2017-05-30 12:17

    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.

    打赏 评论

相关推荐 更多相似问题