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 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画