note 116247 deleted from function.preg-replace by cmb

From: Date: Mon, 21 Nov 2016 19:38:36 +0000
Subject: note 116247 deleted from function.preg-replace by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-207306@lists.php.net to get a copy of this message
Note Submitter: thegatekeeper1978 at gmail dot com ---- "preg_replace" is able to be exploited with a DOS attack by the user submitting a very long string. One way I combat this is by using "substr" first to grab the first part of the string. $input_string = $_GET['user_input']; // If necessary you can log any user attempts to submit a long string $string_length = strlen($input_string); if($string_lenght > 100){log_func($_SERVER['REMOTE_ADDR'], $string_length, $input_string);} $input_string_cut = substr($input_string,0,100); $string = preg_replace('/[^a-zA-Z0-9]/', '', $input_string_cut); echo($string);

« previous php.notes (#207306) next »