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)

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

报告相同问题?

悬赏问题

  • ¥100 支付宝批量检测实名工具
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题