doubu5035 2016-03-03 18:15 采纳率: 100%
浏览 38
已采纳

MySQLi与config.php中的变量连接

I am creating a database connection class, that will access the variables or constants defined in the config.php. However, if I am going to create a theme and a plugin engine, how would I only allow the MySQLi connection class to access the config without allowing plugins/themes accessing the information breaching the security of the website & users.

Previously, I just defined host, username, password, and database as constants in the config, then included the config inside a file that included all of the core website files, such as the core functions file, database connection, etc - I believe this is how popular CMS's such as Wordpress, etc, does it? If not please correct me.

If I include the config inside the database class, but then include the database class inside the website, the config can be accessed by custom code inside the themes and plugins - which MUST NOT happen.

How would I go about doing this? I cannot think of any other way.

Thanks, Kieron

  • 写回答

1条回答 默认 最新

  • duanbenzan4050 2016-03-03 18:22
    关注

    how would I only allow the MySQLi connection class to access the config

    You don't. Instead you should give your MySQLi wrapper class all the settings it needs. ie:

    class MySQLiWrapper {
        public function __construct($server, $username, $password, $database) {..}
    }
    

    As for internal security. PHP code has no sandboxing, any script can do an fopen on any file and read it's contents. Think about how you want to approach security.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)