Is there a way to hide all database info such as password, username, etc?

偶尔善良 提交于 2019-12-01 14:33:32
Michael Borgwardt

While PHP files are executed and thus the source code is not visible from the web, an accidental misconfiguration could change this. You could put the DB configuration in a separate file outside the wbeserver's document root directory and use PHP's require command to include it in the other scripts.

However, depending on the PHP configuration, files outside the docroot may not be accessible to PHP scripts, but there are ways around this. This SO question discusses these issues in detail

If you don't want to put the credentials in php files then you can put them the php.ini configuration file.

mysql.default_host = "localhost"
mysql.default_user = "user"
mysql.default_password = "pass"

then in the php source:

<?php

$connect_db = mysql_connect();
$err = mysql_error();
if ($err != "")
{
        echo "Error connecting to database: $err";
        die;
}

if (!mysql_select_db("mydomain_com_test", $connect_db))
{
        echo mysql_error()."<br/>";
        die;
}

$sql = "SELECT NOW()";
$rows = mysql_query( $sql );

?>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!