开发者

Storing global settings, configurable from an admin page in PHP

I'm looking for the most efficient way to be able to set some basic site-wide settings (probably in boolean or just small numbers) from an admin panel, and have them retrieved on every page (via a common file) and stored in PHP variables.

Specifically, I have a points system on my site, and I'd like to be able to have other site managers be able to set the rewards and costs, and have them be already stored in a variable on every page.

Looking into how a popular forum software had stored settings, they used a MySQL table with rows id, name, and value. Name being the name of the option, and value being the selected value. I didn't look into how this was retrieved in the code itself though, and if it was checked on every run of the common/header file. It seemed to me that having a MySQL query on every page for settings that rarely change wouldn't be very efficient.

Another thing I co开发者_高级运维nsidered was having a text file that just stored the options in JSON.

Let me know if one of these ideas would work, or if there is something that would be more ideal. I'm open to anything.


Storing application-wide configuration settings there is really a misuse of the database. While the performance penalty itself is usually negligible however.

The most efficient approach is certainly a data file. Instead of json_encode you might as well use serialize or generate a valid .php script with just:

file_put_contents("config.php",
     '<?php $config = ' . var_export($config_array, 1) . '; ?>');

The effort for a simple admin ui is likewise small, if you only need a few settings.

For an overkill solution see http://milki.include-once.org/genericplugins/genconfig.html


I have seen a php site that store common setting variables in a php file . And then on other php files you require_once( ) ;

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜