I'm helping someone to create an online database. All is fine and good
except for one problem. Here it is:
In order to provide connectivity to the database, I've created a file called
database.php which is readable only by the Apache web server.
It contained the following:
<?php
function database() {
$db = mysql_connect(" localhost", "mtlstats", /* the password */);
mysql_select_db ("mtlstats", $db);
return $db;
}
?>
I quickly realized that even though nobody could read the password from the
file, there was nothing preventing the other people with accounts on my web
server, from including this file into one of their own php scripts, and
hijacking the database. I therefore made a change, so that it would only
work when called from a file in the /mtlstats directory.
The file now reads as follows:
<?php
function database() {
if(strpos($PHP_ SELF, "/mtlstats/") === 0) {
$db = mysql_connect(" localhost", "mtlstats", /* the password */);
mysql_select_db ("mtlstats", $db);
return $db;
}
return NULL;
}
?>
Unfortunately, I've discovered that although $PHP_SELF normally returns the
name of the file being processed by the server, when called from within a
function, it returns NULL for some reason. Can anyone suggest an
alternative means of correcting this problem?
Any assistance would be greatly appreciated.
--
Jonathan Lamothe
Founder of the Anime Void.
except for one problem. Here it is:
In order to provide connectivity to the database, I've created a file called
database.php which is readable only by the Apache web server.
It contained the following:
<?php
function database() {
$db = mysql_connect(" localhost", "mtlstats", /* the password */);
mysql_select_db ("mtlstats", $db);
return $db;
}
?>
I quickly realized that even though nobody could read the password from the
file, there was nothing preventing the other people with accounts on my web
server, from including this file into one of their own php scripts, and
hijacking the database. I therefore made a change, so that it would only
work when called from a file in the /mtlstats directory.
The file now reads as follows:
<?php
function database() {
if(strpos($PHP_ SELF, "/mtlstats/") === 0) {
$db = mysql_connect(" localhost", "mtlstats", /* the password */);
mysql_select_db ("mtlstats", $db);
return $db;
}
return NULL;
}
?>
Unfortunately, I've discovered that although $PHP_SELF normally returns the
name of the file being processed by the server, when called from within a
function, it returns NULL for some reason. Can anyone suggest an
alternative means of correcting this problem?
Any assistance would be greatly appreciated.
--
Jonathan Lamothe
Founder of the Anime Void.
Comment