Reputation: 338
While working on a web application I stumbled upon something which i cannot find an answer to. Let me present the case:
I have a webpage ( written in php, I have a login system ) in which the user can rearrange graphic elements like, the width of the side bar, the height of the header, rearrange the menu and etc. The question I would like to ask is how to store this preferences? because I want them to remain the same in any browser on any PC, so cookies or sessions are not an option. Do I save them in the database? Is this a good practice?
Upvotes: 0
Views: 36
Reputation: 132
good practice :
As you want setting to remain constant , the EASY way is to use database.
Why ?
Because if your user access site from other computer (like from office computer) he will see a totally default page ! which does not serves purpose . COOKIES or SESSION will not allow you to do so.
How to and which database will be simplest to implement :
I will recommend MYSQL database , because it will be faster (fast really holds meaning because the SETTINGS will be required often to DISPLAY PAGES in browser and delay in loading pages will be irritating to users).Its is also easy to store data.
About security as SETTINGS are not so confidential MYSQL provides OK security.
Other ways ?
Creating a .css file dynamically :
In This case we create a css file for each user differently and include it into HTML CODE by SRC attribute.
Example :
Css file :
<style>
#menu{
height : 200 px;
width :100 px;
}
</style>
Html page
<style src='css_file_path.css'></style>
//you can use LINK tag too.
Now you will have to use **PHP read write and append functions to change contents of .css file **
Algorithm :
1) user CHANGE setting.
2)changing settings trigger a function which will
LINK to php write function
Advantage :
Disadvantage :
Upvotes: 1