H
H
hunter_outlaw2016-06-30 13:59:00
PHP
hunter_outlaw, 2016-06-30 13:59:00

How to store an array of user data? Sessions or cookies?

Hello
There is a task to store an array of 15 publications / products that the user has viewed. Initially, I decided to implement saving the array in sessions.

$_SESSION['lastview']['adsf'][$post['id']]['post_id'] = stripslashes($post['id']);
$_SESSION['lastview']['adsf'][$post['id']]['title'] = stripslashes($post['title']);
$_SESSION['lastview']['adsf'][$post['id']]['posters'] = $post['posters'];
$_SESSION['lastview']['adsf'][$post['id']]['price'] = stripslashes($post['price']);
$_SESSION['lastview']['adsf'][$post['id']]['currency'] = stripslashes($post['currency']);
$_SESSION['lastview']['adsf'][$post['id']]['url'] = $post_url;

But since I don't have much experience with sessions, I'm not sure if I'm doing the right thing. Is it possible to store such data in sessions. In addition, after closing the browser, sessions are cleared, and I need to save this data for as long as possible (for example, before logout)
What is the best way to store such data in order to avoid using the database?
Thank you in advance!

Answer the question

In order to leave comments, you need to log in

4 answer(s)
T
ThunderCat, 2016-06-30
@hunter_outlaw

If the task is to avoid storage in the database, then the option with storage in cookies excludes integrity, the logged-in user will see different data on different devices. When stored in a session - when logout / login from another device, all data goes to the mountains, respectively, this option is also not correct, because I will not see the same thing at home as from work.
I would write to the database, like on aliexpress and eBay, and it’s useful for statistics, and for hints like “people who looked at this product also looked at ..." at the edge - a keyvalued chent, radish for example with an unlimited field, but after a reboot to any data will be gone. Writing and pulling 15 rows from the database takes milliseconds, and the profit in the future is not bad.

R
Rikcon, 2016-06-30
@Rikcon

Take a quick key-value store like redis and write whatever you want there.

M
Maxim Timofeev, 2016-06-30
@webinar

Maybe in localstorage. Will be stored by the user.

H
hunter_outlaw, 2016-06-30
@hunter_outlaw

Thank you all for your help. Perhaps I will do it as follows:
For non-authorized users I will use cookies, and for authorized databases +, if necessary, local storage of the first N records, so as not to constantly pull the database

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question