Jump to content

Website Shortlist


wemustdesign

Recommended Posts

I am creating a 'add to shortlist' feature where users can add items to be viewed later.

 

I don't want the user to have to register to use this feature. What would be the best way to store these items; in a database, cookie or in a session (and maybe save to a database if they register)?

 

It is basically going to work similar to a shopping cart just without the checkout stage and prices

Link to comment
Share on other sites

A universal solution is to create a unique token. Store this token in a table along with the ID of the item and a timestamp as to when the row can be deleted. Store that same token in a cookie. If you only want it to last until the user closes his browser, set the expire time to 0, otherwise, set it to however long you want.

 

When a user adds another item just throw another row into the database, with the cookie's token and the ID of the next item.

 

You can then set up a CRON job, or a garbage collector function (runs randomly) that deletes entries from the table older than the expire date.

 

If you want a registered user to save the data, you can then move those rows into a permanent table without an expire date. You can then rename the cookie to reflect that it's a saved session.

 

Just an idea, you don't have to implement it exactly as stated, but there are some tried and tested ideas in there

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.