Monday 10 June 2019

PHP - Error ASCII=16 State=0 Unexpected Character in Input



I have come across this error for the first time and can't seem to debug it. My code which concerns this error is as follows:



session_start();

$accountUsername = $_POST["username"];
$accountEmail = $_POST["email"];
$accountPassword = $_POST["password"];
$accountPasswordConfirm = $_POST["password-confirm"];
$recaptchaResponse = $_POST["g-recaptcha-response"];
$secretRecaptcha = "XXXXXXXXXXXXXXXX";

// Send Request Of Recaptcha To Google Servers
$verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secretRecaptcha.'&response='.$recaptchaResponse);
$recaptchaValidation = json_decode($verifyResponse, true);


// Validate Recaptcha Response
//if ($recaptchaValidation["success"] == false) {
//echo "error:You must solve the reCAPTCHA verification";
//exit();
//}

// Validate Email Address
$accountEmaili = str_replace("@", "", $accountEmail); $accountEmaili = str_replace(".", "", $accountEmaili);
if (filter_var($accountEmail, FILTER_VALIDATE_EMAIL) && ctype_alnum($accountEmaili)) {

} else {
echo "error:You must enter a valid email address";
exit();
}
if (strlen($accountEmail) >= 5 && strlen($accountEmail) <= 400) {
} else {
echo "error:You must enter a valid email address";
exit();
}


// Validate Username
if (strlen($accountEmail) >= 8 && $accountEmail <= 14) {
} else {
echo "error:Your username must be 8-14 characters";
exit();
}



I have tried to change a few things but nothing works and I have no clue what this error code means too. Could anyone help debug this issue with me, many thanks.





Error: Warning: Unexpected character in input: '' (ASCII=16) state=0 in /home/nodebase/public_html/WebApp/Backend/UserPortal/Register/CreateAccount.php on line 27



Warning: Unexpected character in input: '' (ASCII=16) state=0 in /home/nodebase/public_html/WebApp/Backend/UserPortal/Register/CreateAccount.php on line 27




Line 27 = if (strlen($accountEmail) >= 5 && strlen($accountEmail) <= 400) {


Answer



As said in comments, there are hidden (unicode) characters in your code that is probably caused by your host's editor.




By copying/pasting the following that I mentioned in comments, will solve this for you.



if (strlen($accountEmail) >= 8 && $accountEmail <= 14) {


FYI: The hidden characters were before the > and the < operators.



ASCII 16 is what's called a "DATA LINK ESCAPE" character.



Pulled from https://en.wikipedia.org/wiki/Control_character:





The data link escape character (DLE) was intended to be a signal to the other end of a data link that the following character is a control character such as STX or ETX. For example a packet may be structured in the following way (DLE) (DLE) .




Pulled from https://www.pcmag.com/encyclopedia/term/40801/data-link-escape:




A communications control character that indicates that the following character is not data, but a control code.




No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...