创建PHP INI / CONFIG文件并确保其安全的最佳实践 [英] Best Practices for creating a PHP INI/CONFIG file and keep it secure

查看:78
本文介绍了创建PHP INI / CONFIG文件并确保其安全的最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我总是使用普通的PHP文件并只是在该文件中定义了变量,但这被认为是最佳做法吗?

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

示例:

<?php

define('DB_PASS', 'p@ssw0rd');

?>


推荐答案

这是非常安全的,我认为没有是常量的任何最佳实践,但是出于可读性的考虑,我倾向于将它们收集在专用的 Constants 类中:

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';
}

这篇关于创建PHP INI / CONFIG文件并确保其安全的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆