2

也许是幼稚的问题,但我读过我应该将我的 MySQL 数据库密码和数据库名称保存在受限制文件夹中的单独文件中,但为什么呢?当我使用开发人员工具检查网页时,我看不到 PHP 代码,我错过了什么?

4

3 回答 3

4

Well, firstly, it gives you a single place to set the password so you're not having to edit multiple files if/when the details change

Secondly, you need to consider other users on your system - is it possible that you might want to allow another developer to make changes to your site code without revealing your mysql login details? If so, you can deny them access to that folder but still allow them to edit the rest of the code base.

于 2012-11-12T16:39:40.363 回答
2
  1. 在某些情况下,服务器错误/错误配置导致 PHP 代码显示在用户的浏览器中(参见:几年前的 Facebook)。因此,许多开发人员将他们的 MySQL 连接详细信息放在一个文件中,该文件位于 Web 根目录之外。
  2. DRY原则:不要重复自己。即没有重复代码。这使得代码更易于管理。想象一下,仅仅因为您的 MySQL 密码更改而不得不编辑 500 个 PHP 文件是多么困难?如果您必须连接到不同的 MySQL 服务器怎么办?
于 2012-11-12T16:44:41.070 回答
1

实际上,我们建议将每个凭据放在单独的文件中,而不仅仅是 mysql 用户名和密码。

  1. 这是因为您的生产服务器可能有不同的密码和用户名。因此,要在任何地方反映变化,require最好在您的文件中使用单个文件和它。
  2. 使用源代码控制,我们可以轻松地忽略它,以便团队成员之间不共享密码。
  3. 700我们主要需要对该文件给予特殊许可。
  4. 遵循 DRY 是很好的做法(不要重复自己的原则)
于 2012-11-12T16:49:05.197 回答