I'm on the school server. So before I start I need to say I don't have a choice. I'm tired of reading post with nothing more than "Tell your administator to upgrade". I know. Stop. If I see it its getting flagged as spam.
I don't really understand what about PHP makes it so vulnerable to an injection attack. I'm supposed to use dreamweaver for development and they create this function for mysql:
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_e$
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
and then there is "mysql_real_escape string()".
Wouldn't I just be better off with a strict policy with alphanumeric letters only for input, and check against preg_match("/[A-Za-z0-9]{8,20}/",$input,$match); if(implode($match)!=$input) { exit_error();} ?
(you know since I'm intrigued by regex)
ok so I can't have AWESOME usernames like xX_Ki11er_Qu33n_Xx ~-imma teen grrrl!
-~ or some nonsense.
Shouldn't that be good enough?
its not possible to enter an injection attack if I do a check like that right? Does preg_match read special or unreadable character?