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.