So few days ago i was doing my research and i found out that some functions were not so safe when it comes to preventing certain attacks(cross site scripting),So i decided to create my own function to sanitize user input...
<?php
function sanitize($a)
{
//add your own characters and keywords into the array
$illegals = array("script","javascript","<",">","%","(",")","/","../","alert","'","xss","&","'","=","OR","SELECT","FROM","DROP");
$replace = array("**");
$sanitized = str_ireplace($illegals,$replace,$a,$count);
if ($count > 0 )
{
//attackers payloads will just be left in our database which is a waste of space
header("Location:");
}
else
{
return $sanitized;
}
} // end of function
$email = $_POST["email"];
$password = $_POST["password"];
$cleanemail = sanitize($email);
$cleanpassword = sanitize($password);
//other code
?>
I have tried multiple xss payloads and so far none have being successful.What do you think? Any improvements that can be done?