Answer the question
In order to leave comments, you need to log in
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;
Answer the question
In order to leave comments, you need to log in
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.
Take a quick key-value store like redis and write whatever you want there.
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 questionAsk a Question
731 491 924 answers to any question