PHP - 创建多个 cookie 文件
我读到每个域可以有 20 个 cookie,每个文件 4kb。
我目前正在设置这样的cookie:
setcookie($cookieName, $cookieData , time()+60*60*24*30, "/");
如果名称是“One”并且数据是“111111111”...然后我设置另一个cookie“Two”与数据“222222222”...然后我有一个包含以下数据的文件
One
111111111
192.168.1.2/
1536
673206400
30159100
1505317760
30153065
*
Two
2222222222
192.168.1.2/
1536
983206400
30159100
1820257760
30153065
*
我如何创建两个不同的文件?我想突破我们 Intranet 站点 cookie 的最大大小只能为 4kb 的限制。所有这些 cookie 文件都来自同一个站点...
I have read that you can have 20 cookies per domain, 4kb per file.
I am currently setting cookies like this:
setcookie($cookieName, $cookieData , time()+60*60*24*30, "/");
if name is "One" and data is "111111111"... then i set another cookie "Two" with the data "222222222"... i then have a single file with the below data
One
111111111
192.168.1.2/
1536
673206400
30159100
1505317760
30153065
*
Two
2222222222
192.168.1.2/
1536
983206400
30159100
1820257760
30153065
*
How do i go about creating two different files? I want to pass the restriction of only being able to have a max of 4kb for our intranet site's cookies. All of these cookie files would be from the same site...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您通常不想为此使用 cookie,而是启动一个 会话 (使用cookie来识别用户),并将信息存储在服务器端。
或者,如果会话生命周期对于您的目的来说太短,请创建一个生命周期较长的 cookie,并在其中存储随机密钥。使用该密钥在服务器端存储和查找您的数据。
如果您必须在本地存储内容,则有更成熟的客户端存储策略可以接受更多的数据。请参阅
本地存储 - HTML5 演示(含代码)
客户端数据存储,DOM存储还是HTML5本地存储?
You would usually not want to use cookies for this, but start a session (that uses a cookie to identify the user), and store the information on server side.
Alternatively, if the session lifetime is too short for your purposes, create a cookie with a longer lifetime, and store a random key in it. Use that key to store and look up your data on server side.
If you must store stuff locally, there are more developed client-side storage strategies that can accept more data than that. See
Local Storage - HTML5 Demo with Code
Clent-side data storing,DOM storage or HTML5 Local Storage?