读取多个cookie的方法

发布于 2024-12-07 19:53:18 字数 465 浏览 2 评论 0原文

如果用户确实查看了该线程,我会为他存储一个 cookie - 该 cookie 包含每个线程中最后一个帖子的 unix 时间,然后我比较实际 cookie 数据和线程最后一个帖子之间的时间。

每个不错的论坛都有一个包含部分和论坛列表的默认页面。现在如何读取我在论坛的每个线程中为此类帖子存储的cookie?

我在想这样的事情:

foreach( $threads as $thread ) {
 if($_COOKIE[@PREFIX."_thread".$thread['id']] < $thread['lastpost'])
   //do action , in case if there are some new posts
 else
   //do action, in there aren't new posts.
}

我现在必须解析 10 个,以后甚至数千个线程。会严重影响服务器性能吗?

I'm storing a cookie for user if he did view the thread - the cookie contains unix time of the last post in each thread, then I'm comparing the time between actual cookie data and the threads last post.

Every nice forum, has a default page with sections and forums list. Now how to read those cookies I was stored for such post in each thread of a forum?

I was thinking at something like:

foreach( $threads as $thread ) {
 if($_COOKIE[@PREFIX."_thread".$thread['id']] < $thread['lastpost'])
   //do action , in case if there are some new posts
 else
   //do action, in there aren't new posts.
}

I'll have to parse now 10 and later even thousands of threads. Will it hurt alot the server performance?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

离不开的别离 2024-12-14 19:53:18

我认为这不是一个好方法,因为没有论坛软件可以做到这一点。其一,如果用户清除 cookie,或使用不同的浏览器,那么所有这些都将丢失。

假设您有一个线程和用户表,我会添加另一个表来记录他们上次看到该线程的时间。

TABLE user_thread_view
{
    thread_id
    user_id
    created (timestamp)
}

然后,当您提取该论坛上的线程列表(每页 10-20 个)时,您可以向该表添加一个调用,以查看该用户和线程的“创建”匹配项是否小于当前的 last_modified线。

I don't think this is a good way to do this based on the fact that no forum software does. For one, if the user clears the cookies, or uses a different browser then all this will be lost.

Assuming you have a thread and user table I would add another table to record when they last saw that thread.

TABLE user_thread_view
{
    thread_id
    user_id
    created (timestamp)
}

Then when you pull out the list of threads on that forum (which is 10-20 per page) you can add a call into this table to see if the "created" match for this user and thread is less than the current last_modified of the thread.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文