Answer the question
In order to leave comments, you need to log in
Changing the look of the directory "on the fly" by replacing the class. How to save?
Hello!
There is a product catalog, the appearance of which can be changed without reloading the page, by changing one css class (gallery, list, grid). But when turning pages, or changing the sort order or turning on filters, the catalog page is reloaded and the selected view is not saved.
Right now I'm using a js cookie to store a variable that defines the appearance of the directory. As a solution, I think you can store this variable in $_SESSION.
It seems that the simplest and most correct thing would be to simply add the appropriate variables to the a href="" tag on the page, at the same time as changing the class. But here you need to track whether there are already variables in the GET request or not (to choose what to add: ?gallery or &gallery),
In general, I do not like all the options for their bulkiness. How to do it right, advise?
Answer the question
In order to leave comments, you need to log in
I had a similar task, I did it through cookie js.
The choice is at least good because after the visitor visits the site again, he will be shown the output in a format convenient for him, because sometimes it’s annoying when you visit again to change the output format for yourself
Sessions are typically used to store information that should be user-specific, but that needs to be protected from being viewed or modified.
Cookies are ideal for storing information personalized for the user, if it does not contain any secrets from him and the change of which will not affect anything important for the site / server.
Plus, sessions are limited in time, and cookies with settings can be saved for a reasonable period (week, month) so that a user who visits the site on a regular basis always sees his theme settings. Even more thorough - store them in the database for registered users, and in order not to pull the database every time - store them in cookies again)
In addition, everything in the session loads your server, a million users - a million files with an array of settings. Do not abuse this storage. Of course, several variables or arrays will not burst, but you should not take it as a practice to massively store serialized objects in the session, large arrays of information, or data that is static for all users.
PS: As for the argument in the link - the worst idea... The link can be sent to a friend, will people arbitrarily pass different design options to each other?)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question