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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?