Forum Moderators: coopster
function registerUser($user, $pass, $email, $first_name, $last_name, $phone, $alt_phone, $fax, $agree) {
$user = mysql_real_escape_string(stripslashes($user));
$pass = mysql_real_escape_string(stripslashes($pass));
$email = mysql_real_escape_string(stripslashes($email));
$first_name = mysql_real_escape_string(stripslashes($first_name));
$last_name = mysql_real_escape_string(stripslashes($last_name));
$phone = mysql_real_escape_string(stripslashes($phone));
$alt_phone = mysql_real_escape_string(stripslashes($alt_phone));
$fax = mysql_real_escape_string(stripslashes($fax));if (checkIfUser($user)){
return 1;
}elseif (!validateEmail($email)){
return 2;
}elseif (!validateUsername($user)) {
return 3;
}elseif (checkIfEmail($email)) {
return 4;
}elseif ($agree!= "agree") {
return 5;
}elseif ($pass == "") {
return 6;
}else {
// Get remote IP
$ipaddress = getenv('REMOTE_ADDR');
$reg_date = date("Y-m-d H:i:s");
//Encrypt password for database
$salt = 's+(_a*';
$pass = md5($pass.$salt);
$sql = "INSERT INTO users (ipaddress,user,pass,email,first_name,last_name,phone,alt_phone,fax,reg_date) VALUES ('" . $ipaddress . "', '" . $user . "','" . $pass . "', '" . $email . "', '" . $first_name . "', '" . $last_name . "', '" . $phone . "', '" . $alt_phone . "', '" . $fax . "', '" . $reg_date . "')";
$result = mysql_query($sql);
return 99;
}
}
I would also like to let some of you look at it for an external code review if you would be willing this will be a project hosted on sourceforge and I appreciate any comments.
Best Regards,
Brandon
$user = mysql_real_escape_string(([url=http://us2.php.net/get-magic-quotes-gpc]get_magic_quotes_gpc[/url]())? stripslashes($user): $user);
Try that.
$user = mysql_real_escape_string((get_magic_quotes_gpc())? $user: addslashes($user));
than to pull data that has been addslashed I just do this
function getUserRecords($user) {$sql = "SELECT * FROM users WHERE user = '" . $user . "'";
$res = mysql_query($sql);
$c=0;
while ($a_row = mysql_fetch_array($res)) {
$records[$c]["user"] = (get_magic_quotes_gpc())? $a_row["user"]: stripslashes($a_row["user"]);
$c++;
}
return $records;
}
Would the above code be correct?
Thanks for all of your help pointing me in the right direction.
Best Regards,
Brandon
excerpted from about halfway down the page
4> You should never need to use stripslashes on output from a database. Aside from security, escaping quotes for instance, is solely for the benefit of the SQL parser. This is no different than escaping quotes in PHP strings, in order to not confuse the PHP parser and get an error. If you echo the string, it will not contain the escape characters, they are there solely to tell the parser what language characters are intended to be part of the string, and which ones are to be interpreted as actual code. The SQL parser in a database is no different.
5> Magic quotes and addslashes are vulnerable to character set differences and should not be used. If you can't turn it off, run code to defeat it, which is the proper use of stripslashes.
referenced from this post [webmasterworld.com...]
Regards,
Brandon