- Joined
- Feb 19, 2003
- Messages
- 243
- Reaction score
- 0
Hi, I'm currently working on a new system for my website which will use a MySQL database. Usually I don't like using MySQL because I don't know how to secure it properly. So far by reading some stuff on the PHP website I have managed to slap together two functions called MakeSafe and MakeReadable. MakeSafe is run on all $_GET and $_POST data before entering it into the database, and MakeReadable is run on all data returned from the database before outputting it to the screen.
Basically what I'd like to know is whether or not this is secure against SQL exploits.
Thanks.
Basically what I'd like to know is whether or not this is secure against SQL exploits.
Code:
function MakeSafe($string, $dbcon)
{
// Get rid of HTML
$string = htmlentities($string);
// Reverse magic_quotes_gpc/magic_quotes_sybase effects on those vars if ON.
if(get_magic_quotes_gpc()) {
if(ini_get('magic_quotes_sybase')) {
$string = str_replace("''", "'", $string);
} else {
$string = stripslashes($string);
}
}
// Make a safe string
$string = mysql_real_escape_string($string, $dbcon);
return $string;
}
Code:
function MakeReadable($string)
{
$string = stripslashes($string);
// Fix anything that htmlentities broke
$str = array("£");
$rep = array("£");
$string = str_replace($str, $rep, $string);
return $string;
}
Thanks.

