I got this code from a youtube video, code is really useful but I want to improve it security:
function escape($string) {
$str = trim($string);
return htmlentities($strfinal, ENT_QUOTES, 'UTF-8');
}
together with the Input class:
class Input {
public function exists($type = 'post') {
switch ($type) {
case 'post':
return (!empty($_POST)) ? true : false;
break;
case 'get':
return (!empty($_GET)) ? true : false;
break;
}
}
public static function get($item) {
if(isset($_POST[$item])) {
return $_POST[$item];
} elseif(isset($_GET[$item])) {
return $_GET[$item];
}
return '';
}
}
It would be very useful for atleast must of us that it should call the escape function inside the input class so every string of input ALWAYS gets checked even if we "forget" to call it in our apps.
So to be short is there a way to escape all input for most things we dont want, without that escaping makes the app even slower? So its these two scripts in combination with eachother.
Thanks!