SessionStorage Javascript =/= PHP? [英] SessionStorage Javascript =/= PHP?

查看:34
本文介绍了SessionStorage Javascript =/= PHP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 SessionStorage 中使用 Javascript 编写了一个值为4"的变量级别".

I wrote in SessionStorage a variable "level" with value "4" with Javascript.

sessionStorage.setItem('level', 4);

但是当我想用 PHP 读取它时,它会出错:/

But when I want to read it with PHP, it makes error :/

echo $_SESSION["level"];

问题图片

我该如何解决这个问题?

How can I resolve this problem ?

推荐答案

JavaScript 会话存储与 PHP 会话完全没有共同之处.前者归客户端(浏览器)所有,只能在客户端上下文中访问,而后者存在于服务器上,通常通过 cookie 连接到浏览会话.

The JavaScript session storage has absolutely nothing in common with the PHP session. The former is owned by the client (browser) and can be accessed only in the client context, while the later exists on the server and it's connected to the browsing session, usually through a cookie.

您需要多阅读以了解它们的工作原理,但长话短说,它们没有任何共同点.

You need to do more reading to understand how they both work, but long story short, they have nothing in common.

对于 JavaScript,在浏览器中:https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage

For JavaScript, in browser: https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage

对于 PHP:http://php.net/manual/en/intro.session.php

这篇关于SessionStorage Javascript =/= PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆