I have a php file that holds my login details named “connect.php”.
$host = 'localhost';
$username = 'username';
$password = 'password';
$database = 'database';
And I’m trying to connect with another file (html) with this as its contents:
$a = file_get_contents("http://example.com/folder/connect.php");
echo ($a);
mysql_connect ("$host", "$username", "$password");
@mysql_select_db($database) or die("Unable to select database");
And it keeps on giving me this error:
Warning: mysqli_connect() [function.mysqli-connect]: (28000/1045): Access
denied for user '**wrong username**'@'localhost' (using password: NO) in
/home/path/public_html/repo/path/downloads.php on line 40
Instead of
You should be using require/include:
Your current code still won’t work using HTTP since you’d need to eval or parse the result to assign your
$usernameand$passwordvariables, just outputting the result of the PHP script doesn’t assign any variables.You shouldn’t need to (or be able to) use http to download your MySQL connection information through HTTP especially with no authentication. That is a big security issue. If that is your setup you should change it, so that you have a local configuration file stored outside of your web root which has your db host, username, and password in it.