Jump to content

help with sessions


MDanz

Recommended Posts

i have a forum, with new posts how do i use sessions for each user to determine if the posts clicked on and not?  I'm guessing sessions because that is individual to the user...

 

e.g. 

 

new post, then click on not new post.

 

 

i can't assign this to the actual post or then it would display as not new post for other users that haven't seen it.

 

any tips?

Link to comment
Share on other sites

If you want the site to know if a user has accessed a topic over multiple visits, you will need to store this information in a database.

 

If indeed it is only for the current session (that is, a single visit to the site) you can store it in a session and I'd do something like this...

 

Each time a user accesses a topic

$_SESSION['viewed'][$TOPIC_ID]=1;

And on the list of topics, for each topic check...

if(isset($_SESSION['viewed'][$TOPIC_ID])){
  // This topic has been viewed
}else{
  // This topic has not been viewed
}

Link to comment
Share on other sites

An easyer way to do something similar is to place a cookie at the last visit, and all posts after that visit are 'new'. Ofcourse this isn't what you want, but it's a possibility.

With Sessions you always have to store it in a database; otherwise it will be lost information after the user closes his browser.

Link to comment
Share on other sites

If you want the site to know if a user has accessed a topic over multiple visits, you will need to store this information in a database.

 

If indeed it is only for the current session (that is, a single visit to the site) you can store it in a session and I'd do something like this...

 

Each time a user accesses a topic

$_SESSION['viewed'][$TOPIC_ID]=1;

And on the list of topics, for each topic check...

if(isset($_SESSION['viewed'][$TOPIC_ID])){
  // This topic has been viewed
}else{
  // This topic has not been viewed
}

 

how would i store it in a database though..  i'd have to log ever post to each username? .. or is there another way?

Link to comment
Share on other sites

I've never really worked with any forum software, but I imagine you would need another table (lets call it viewed_topic) that stores the topic id and the user id

 

so each time a user accesses a topic, you add to the viewed_topic table a record for the user_id and the topic_id and make reference to that.

Link to comment
Share on other sites

I've never really worked with any forum software, but I imagine you would need another table (lets call it viewed_topic) that stores the topic id and the user id

 

so each time a user accesses a topic, you add to the viewed_topic table a record for the user_id and the topic_id and make reference to that.

 

thx thats what i thought, but it would take up too many records.

Link to comment
Share on other sites

It can't be done with sessions as such.

What happens is.. you click on a thread/post, you reply. This subscribes you to it (NOT VIA SESSIONS.. AS THIS'LL EXPIRE)

When a new post is submitted, it inserts the info into the database, this is where you email everyone subscribed to this post.. that there is a new reply.

 

You could then have a table called "new_posts" This will consist of.. id, thread_id, user_id. When a post is sent, it inserts a row into this table.. well, .. a row for each user subscribed to the thread.

 

If you have a page to check for new posts. Like this forum does, then you'd check for all rows with the current logged in user_id. Then display thread related to the thread_id on that row.

When you click on the post.. if there is your user_id, with that thread_id in the database, to remove it. As you've viewed it.

 

That's all really. You'll need extra pieces so you don't duplicate rows or anything. :)

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.