Securing your mySQL passwords
One of the biggest problem with shared servers and PHP (in my opinion) is how to secure your mySQL passwords.
If the server is poorly configured, all the other users on the server could gain access to your mySQL passwords with a simple CGI application (No, it's not enough to set php_open_base_dir). But there is a way to make it a bit more secure. So secure that the hacker needs root access to find them, and if the hacker has root access you are doomed anyway. But it requires that you have access to the Apache configuration, or some goodwill from your ISP. Apache enables you to store some environment variables using the SetEnv directive. Let's look at an example:
SetEnv mySQL_USER username
SetEnv mySQL_PASS somePassword
If you place this inside your vhost, the environment variables mySQL_USER and mySQL_PASS will be set to username and somePassword for all requests inside this vhost.
The variables will be available in the superglobal array $_SERVER:
echo $_SERVER['mySQL_USER']."<br />\n";
echo $_SERVER['mySQL_PASS']."<br />\n";
But everything has a downside, this method to. Le's say the phpinfo() function is called in one of your scripts, this will print the whole $_SERVER array, including your mySQL passwords.
Post new comment