Here's the code. This works fine
//check variables
function CheckString($stringToCheck, $stringMaxLength, $validChars) {
if(strlen($stringToCheck) > $stringMaxLength) {
setcookie("main_message", "Variable size<br>invalid!");
header('location:main.php?');
exit;
} else {
//loop through each character
for($chrPos = 0; $chrPos < strlen($stringToCheck); $chrPos++) {
$isValid = 0;
//get the character to audit
$chrAudited = substr($stringToCheck, $chrPos, 1);
for($chrNum = 0; $chrNum < count($validChars); $chrNum++) {
//perform audit
if($chrAudited == $validChars[$chrNum]) {
//Character is valid
$isValid = 1;
}
}
if($isValid == 0) {
//no valid character found at current position
setcookie("main_message", "Invalid character found<br>Valid characters are:<br>A-Z, 0-9, and spaces");
header('location:main.php?');
$stringToCheck = "";
exit;
}
}
}
//If we reach this point, all is well, return string
return($stringToCheck);
}
$validChars = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9',' ');
$user = CheckString(stripslashes($user), 14, $validChars);
$pass = CheckString(stripslashes($pass), 100, $validChars);
I just tried it with the $validChars array defined in the function, and now it's working for some odd reason. I have been encountering some other flakey problems like the header call only working half the time even though echo output shows that the line before and after was run. I think I just need to reboot my PC or something.