douzui0143 2016-10-26 18:02
浏览 36
已采纳

保存可由用户重新排列的网页元素

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?

  • 写回答

1条回答 默认 最新

  • doutao6653 2016-10-26 18:24
    关注

    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
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录