How to secure database passwords in PHP?

后端 未结 16 1246
闹比i
闹比i 2020-11-21 22:41

When a PHP application makes a database connection it of course generally needs to pass a login and password. If I\'m using a single, minimum-permission login for my applica

16条回答
  •  星月不相逢
    2020-11-21 23:20

    The most secure way is to not have the information specified in your PHP code at all.

    If you're using Apache that means to set the connection details in your httpd.conf or virtual hosts file file. If you do that you can call mysql_connect() with no parameters, which means PHP will never ever output your information.

    This is how you specify these values in those files:

    php_value mysql.default.user      myusername
    php_value mysql.default.password  mypassword
    php_value mysql.default.host      server
    

    Then you open your mysql connection like this:

    Or like this:

提交回复
热议问题