How do I implement user preferences on a PHP jQuery page?
On a portal's main page, I'm using a jQuery container plug-in, and by this users can hide a container by just clicking the minimize button on a container.
My question is: how can I save the user preferences in this regard? Then if the same 开发者_Python百科user logs in again, I want to show the page based on user preferences. For example if a user hides the "sports news container" it won't be shown on users next visit.
You just need to create a field in the users database table (or do something more complicated, if your database is complicated).
Then you can, if the field is set, place a script on the page that hides the container. And set a callback on hiding/opening which will send an Ajax request to your application, which will set the field to 1 or 0 (ON or OFF, whatever).
I think there are basically 3 options.
Cookies (sending a cookie to the user with JavaScript/jQuery or PHP (setcookie())) and hope the cookie is stored as long as possible.
Storing the preference at the database level, per user. @valya gave a solution like that. The obvious drawback here is that every user of the site, that you want to have preferences, needs a login.
Storing the preference in the database by IP address. This solution is pretty bad, but depending on your users this might work. So you store preferences per IP address. Users with a dynamic IP address or multiple users on the same IP address will have a bad experience.
精彩评论