AIM

MSN

Website URL

ICQ

Yahoo

Jabber

Skype

Location

Interests

Languages

Hi all, I have a php file to check a users input and it seems pretty straight-forward as far as logic goes, but the variable seems to be concatenating the "badEntry" onto its return value. I've been over it and over it and can't seem to see what's wrong. I originally had $userInput as the only return variable, but when I started having trouble I added the $toReturn variable to hopefully make it clear what I was doing wrong. Didn't help. I enter 'sakde12345' and I get that back with 'BadEntry' concatenated to it - looks like this - sakde12345BadEntry. My callback function is supposed to see if the return value is equal to 'BadEntry' and of course it isn't because it somehow includes the original input in front of it. It's returning this for either 'good' or 'bad' input. Can anyone figure out how I've miscoded or what? I also had a question about the debugger in chrome when I was running the js that called this php in the xmlhttprequest. The debugger traced thru everthing OK, but when it came to the 'onreadystatechange', it went to the 'xhr.open' line, jumped back to the onreadystatechange ( which became 1) but then it jumped to the requestheader line, then the .send line, then it jumped back to the js function that called the xhr request, then it jumped all the way back to the button in html that submitted the input. That kind of surprised me to see that - is the program just gathering information to proceed or something like that? I know it's kind of a weird question, but I'd like to understand what is going on. Thanx for any help, and I appreciate your patience!!!
<?php
$toReturn = "";
$userInput = "";
$chars = [];
$i = 0;
if ($_SERVER["REQUEST_METHOD"] == "POST"){
$userInput = $_POST["userID"]; // Get variable passed to xmlhttp call
$userInput = test_input($userInput); // Run it thru easy data cleaner
$userInput = strtolower($userInput); // change all to lower case
$toReturn = $userInput;
$chars = str_split($userInput); // split input into single characters
if (strlen($userInput) != 10) { // is the input exactly 10 chars long
$toReturn = "BadEntry";
} else {
if (substr($userInput,0,3) != "sak") { // are the 1st 3 letters 'sak'
$toReturn = "BadEntry";
} else {
if (is_not_Char($chars[3]) || is_not_Char($chars[4])) { // are the 4th & 5th chars letters - name initials
$toReturn = "BadEntry";
} else {
for ($i = 5; $i < 10; $i++){
if (is_not_Numb($chars[$i])) { // are the last 5 chars Numbers
$toReturn = "BadEntry";
}
}
}
}
}
}
echo $toReturn;
function is_not_Char($examp){
$charBool = false;
if ($examp < chr(97) || $examp > chr(122)) { // is it a lowercase letter - ascii 97 - 122
$charBool = true;
}
echo $charBool;
}
function is_not_Numb($examp){
$charBool = false;
if ($examp < chr(48) || $examp > chr(57)) { // is it a number - ascii 48 - 57 ( 0 - 9 )
$charBool = true;
}
echo $charBool;
}
function test_input($data) { // standard data cleansing tools
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
echo $data;
}
?>