doqrt26664 2014-07-04 02:20
浏览 56
已采纳

覆盖我的CMS的配置文件

I'm looking for the best options besides storing the values in a mySQL db, I'd rather have a singular file for my defines or variables.

What I need to do is have a configuration.php file which I have one already for my admin panel which I've filled out, but inside the admin panel they will be able to edit stuff such as the page title or anything basic for that matter. So I was thinking I could have a static_configuration.php file which would hold all the data that I need.

EX Before Edit (static_configuration)

define("_TITLE","{TITLE}");
define("_DESC_","{DESC}");
define("_KEYW_","{KEYW}");

My idea is to use this as a template, and when they edit, I'll fopen fwrite etc to basically overwrite configuration.php

EX After Edit (configuration.php)

define("_TITLE_","Great Turns");
define("_DESC_","Great turns is a turned based RPG online game......");
define("_KEYW_","great turns online rpg, great turns");

My idea works, and I've implemented it something like this so far

if(file_exists('static_configuration.php')){
      $file= file('static_configuration.php', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
      foreach($file as $configs){
        $channel.= str_replace(array('{TITLE}','{DESC}','{KEYW}'),array("BASE TURN","This is a website","cool,dude,whats up"),$configs);
      }
    $data = fopen("configurations.php","c+");
     fwrite($data,$channel);
     fclose($data);
  }

Question in hand is this a safe bet or should I take a different route? I mean I need to make the code a little bit more dynamic using $_POST requests but so far it does work. Please enlighten me as I am just trying to learn and write a simple CMS (My thoughts are don't use something unless you know how it works), college also will have me writing a lot of these methods so I am asking out of curiosity.

  • 写回答

1条回答 默认 最新

  • dsjklb0205 2014-07-04 02:26
    关注

    While you escape the data correctly before defining them, i think you will not have probs.

    PS : for reading and writing files, check file_get_contents() and file_put_contents() :P

    But if its more for curiosity, check gettext() methods ;) (i think you do this for language)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器