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 写uniapp时遇到的问题
  • ¥15 matlab有限元法求解梁带有若干弹簧质量系统的固有频率
  • ¥15 找一个网络防御专家,外包的
  • ¥100 能不能让两张不同的图片md5值一样,(有尝)
  • ¥15 informer代码训练自己的数据集,改参数怎么改
  • ¥15 请看一下,学校实验要求,我需要具体代码
  • ¥50 pc微信3.6.0.18不能登陆 有偿解决问题
  • ¥20 MATLAB绘制两隐函数曲面的交线
  • ¥15 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流