/ Published in: PHP
This function is used to cleanse user input data before creating queries to prevent SQL Injection attacks. This should also work to prevent XSS attempts through user input as well.
Expand |
Embed | Plain Text
/* +-------------------------------------------------------------------+ |______________________The_Sterilizer_Function______________________| | PHP 5+ ONLY - Used to prevent SQLI and XSS attacks via user input | | | | 1 *REQUIRED* value, 1 <OPTIONAL> value to call this function: | | $input = User input string to be cleansed | | #is_sql = Boolean. Whether or not $input is a sql query | +-------------------------------------------------------------------+ | Example of use: | | $username = sterilize($_POST['username']); | | $query = "SELECT * FROM users WHERE username = '$username'"; | +-------------------------------------------------------------------+ */ function sterilize ($input, $is_sql = false) { { } if ($is_sql) { } ", "\n", $input); return $input; }
Comments
Subscribe to comments
You need to login to post a comment.

$input = str_replace(" ", "\n", $input);
replece ' ' with \n ? why?