1

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 functions 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?

Charles Sprayberry
  • 7,741
  • 3
  • 41
  • 50
Simon Suh
  • 10,599
  • 25
  • 86
  • 110
  • i prefer define(), or a db for this –  Aug 14 '11 at 04:51
  • define('NAME','Anil'); a better way . List all this way . [ I saw in wordpress ] – Anil Shanbhag Aug 14 '11 at 04:54
  • Is the usage similar to a configuration array? Then http://stackoverflow.com/questions/7054613/storing-global-settings-configurable-from-an-admin-page-in-php - but just from the looks I would advise for a data file here. – mario Aug 14 '11 at 04:54

1 Answers1

1

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  |
AlienWebguy
  • 76,997
  • 17
  • 122
  • 145
  • thanks, I'll be using a db then. for some reason I was under the impressions data base tables weren't supposed to be used for single variable information, lol, i'm basking through the glories of being a self taught web developer haha – Simon Suh Aug 14 '11 at 06:17