dqxhit3376 2011-08-14 04:47
浏览 23
已采纳

在php中创建变量页面的最佳实践?

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?

  • 写回答

1条回答 默认 最新

  • dsfsdfsdfsdfsdf45454 2011-08-14 04:58
    关注

    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  |
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog