网站各个页面上的 Cookie 限制
所以我知道浏览器将 cookie 数量限制为 200 之类的......或者其他什么(想法是有一个限制)。
我需要将网站页面标记为当前访问者查看,因此我设置了一个 cookie viewed=true
。
如何我可以只为某个页面设置cookie吗?我知道这是可能的,我见过网站这样做...
假设我有 10,000 个页面,并且访问者查看了所有页面。如果他的计算机上为每个页面设置了大约 10,000 个 cookie,浏览器会抱怨吗?整个网站(所有页面一起)是否也有 cookie 限制?
更好地解释我想要的内容:
Cookie 可以设置为全局(对于整个网站,在所有页面上可见) ),或本地(仅适用于特定页面)。
如何设置本地 cookie?例如,只能从
访问 cookiesite.com/?page=blablawhatever
Cookie 数量浏览器限制是否也考虑所有本地 Cookie,还是仅考虑当前站点页面的 Cookie?
So I know browsers limit the cookie number to something like 200 ...or whatever (the idea is that there is a limit).
I need to mark a site's page as viewed by the current visitor, so I'm setting a cookie viewed=true
.
How can I set a cookie only for a certain page? I know it's possible, I've seen sites doing this...
Let's say I have 10.000 pages and a visitors views them all. Would browsers complain if there are like 10.000 cookies set on his computer for each of these pages? Is there a cookie limit for the entire site too (all pages together) ?
better explanation of what I want:
Cookies can be set as global (for the entire site, visible on all pages), or local (for a certain page only).
How can I set a local cookie? For example a cookie that's only accessible from
site.com/?page=blablawhatever
Does the cookie number browser limit take in consideration all local cookies too, or just the cookies for the current site page?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以设置会话 cookie 并将查看的页面存储在服务器上。
You can set a session cookie and store the viewed pages on the server.
而不是使用 cookie(位于用户端)。
当用户访问您的某个页面时,将其保存到他/她访问过的数据库中。
在数据库保存之前,用户的检查已经存在,如果是这样,则不要将其保存到数据库中。
Instead of using cookies (which is on the user's end).
When a user goes to one of your pages, save to the data base that he/she went there.
Before the database save check of the user was already there before, and if that is true then don't save it to the database.
我认为理想的方法是设置一个用户 ID cookie,并且像其他人所说的那样,将与该用户相关的任何信息存储在数据库中。
I think the ideal way would be to set a user ID cookie and, like the others said, store any information tied to that user in your database.