I have to create an administrator control panel and I want to create a php page that just contains variables that can be changed by the administrator and that would affect the rest of the website. Is there a specific best practice method for this? I used the array method below because I saw phpBB (open source forum software) using it. (and of course on my actual website, one php file would create just arrays/array and other php files will contain func开发者_JAVA百科tions editing the array variables)
<?php
$acp_array = array(
'apple' => 'red',
'grass' => 'green',
'sky' => 'blue'
);
print_r($acp_array);
echo '<br />';
$acp_array['sky'] = 'purple';
print_r($acp_array);
?>
Also, how would I make the array variable change (in my example the change from blue to purple for the sky variable) permanent? Or is there a better and different way to store php variables that should be used through the site globally?
For an admin control panel I'd recommend setting up your config key=>val pairs in a database. Easily scalable, and you don't have to worry about setting write permissions to a PHP file.
Example table:
Table 'site_config'
| id | key | val |
|_______|_______|_______|
| 1 | apple | red |
| 2 | grass | green |
| 3 | sky | blue |
精彩评论