开发者

Best Practices for creating a PHP INI/CONFIG file and keep it secure

I always used a normal PHP file and just defined the variables in that file, but is this considered best practice?

Example:

<?php

define('DB_PASS', 'p@ssw0rd'开发者_运维知识库);

?>


Naming your PHP file something that begins with .ht (for instance .htconfig.inc.php) also helps, since Apache usually has a rule never to serve any files that are named .ht*. But placing your file outside of the document root is even better.


It is quite safe and I don't think there is any best practice for constants, but I tend to gather them in a dedicated Constants class for readability:

class Constants {
    const DB_PASS = 'mypass';
}


unless someone has access to your PHP source code that is secure.

however I would make sure the file is outside of the document root to prevent problems IF for some reason php gets turned off on the website and all of a sudden people can see the source of your files :).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜