wemustdesign Posted September 18, 2011 Share Posted September 18, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/247365-website-shortlist/ Share on other sites More sharing options...
freelance84 Posted September 18, 2011 Share Posted September 18, 2011 how much later? how many entries are expected? Cookies will do it, but then if they log onto another machine they wont be able to access that information... Quote Link to comment https://forums.phpfreaks.com/topic/247365-website-shortlist/#findComment-1270375 Share on other sites More sharing options...
wemustdesign Posted September 18, 2011 Author Share Posted September 18, 2011 Its going to be a little bit like a estate agent/ real estate website, so the shortlist will hold as many as they add really. To save the shortlist they have created they will have to register but they can initially use the system while they are browsing the webiste for the first time. Quote Link to comment https://forums.phpfreaks.com/topic/247365-website-shortlist/#findComment-1270428 Share on other sites More sharing options...
xyph Posted September 18, 2011 Share Posted September 18, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/247365-website-shortlist/#findComment-1270456 Share on other sites More sharing options...
wemustdesign Posted September 19, 2011 Author Share Posted September 19, 2011 Thats on the same lines as I was thinking about doing it, I didn't want to jump in though. Thanks for the reply Quote Link to comment https://forums.phpfreaks.com/topic/247365-website-shortlist/#findComment-1270779 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.