Netra
Netra

Reputation: 338

Save the webpage elements which can be rearanged by the user

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

Answers (1)

akash raigade
akash raigade

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

  • get which settings are changed (ex: height of menu)
  • Get line number where the height of menu is typed.(i.e line 3)
  • open .css fileby php
  • Write function WRITE to with line number and replace text 100 to new settings.
  • Close file . -BINGO CSS SETTINGS CHANGED ! NO DATABASE NEEDED !

LINK to php write function

Advantage :

  • no database needed
  • absolutly 0 second time to load (where in case of mysql it will be loading settings of separate element at a time).

Disadvantage :

  • Write a some what of more complex code
  • You will have to write at correct lines or something unwanted could happen.
  • TO get correct lines where to write ? you need to search in your .css file

Upvotes: 1

Related Questions