OK, thanks Rob and Beansprout, I thought Rob was saying that I didn't need that big bit of code at the top of my script. I'm going to put that in a different PHP file and include it so everything is neater
OK, I have added that. Does this look right?? Or do I still need the code Beansprout posted as they are different, don't think I do as they have the same type of stuff in them if you know what I mean.
[Edit]
Was reading the SQL escape_string page again looking for something I read yesterday.
"This function must always (with few exceptions) be used to make data safe before sending a query to MySQL." Does this mean I only need to have this coding in queries that post data to SQL or should I have it in ALL queries?
[Edit]
Just read through the whole of Robs security bit on roblog, very good thanks Rob
[Edit]
Should I use Robs code or the code Beansprout posted? They are different but will they do the same thing?
Craig.
OK, I have added that. Does this look right?? Or do I still need the code Beansprout posted as they are different, don't think I do as they have the same type of stuff in them if you know what I mean.
Code:
function remove_magic_quotes($array) {
foreach ($array as $k => $v) {
if (is_array($v)) {
$array[$k] = remove_magic_quotes($v);
} else {
$array[$k] = stripslashes($v);
}
}
return $array;
}
if (get_magic_quotes_gpc()) {
$_GET = remove_magic_quotes($_GET);
$_POST = remove_magic_quotes($_POST);
$_COOKIE = remove_magic_quotes($_COOKIE);
}
//Include the config file
include "config.php";
$username = $_POST['username'];
$password = $_POST['password'];
$rpassword = $_POST['rpassword'];
$pass = md5($password);
if ($username === htmlspecialchars($username)) {
if (($username == "") || ($password == "") || ($password !== $rpassword)) {
echo "Please go back and make sure you have filled everything in correctly<br>";
} else {
$sql = sprintf("INSERT INTO users (username, password) VALUES ('%s', '%s')",
mysql_real_escape_string($username),
mysql_real_escape_string($pass));
[Edit]
Was reading the SQL escape_string page again looking for something I read yesterday.
"This function must always (with few exceptions) be used to make data safe before sending a query to MySQL." Does this mean I only need to have this coding in queries that post data to SQL or should I have it in ALL queries?
[Edit]
Just read through the whole of Robs security bit on roblog, very good thanks Rob
[Edit]
Should I use Robs code or the code Beansprout posted? They are different but will they do the same thing?
Craig.
Last edited: