?=-` '; $chars = str_split($chars); $ch = array(); // fill up $ch until we reach $length while(count($ch) < $length) { $n = $length - count($ch); $keys = array_rand($chars, $n > count($chars) ? count($chars) : $n); if($n == 1) { $ch[] = $chars[$keys]; break; } shuffle($keys); foreach($keys as $key) $ch[] = $chars[$key]; } $chars = $ch; return implode('', $chars); } public static function make_confusing($string) { $chars = str_split($string); foreach($chars as &$c) { if(rand(0, 2) != 0) continue; $c = mb_encode_numericentity($c, array(0, 0xffff, 0, 0xffff), 'UTF-8'); } return implode('', $chars); } public function __construct(array $salt = array()) { global $config; if(!empty($salt)) { // create a salted hash of the "extra salt" $this->salt = implode(':', $salt); } else { $this->salt = ''; } shuffle($config['spam']['hidden_input_names']); $input_count = rand($config['spam']['hidden_inputs_min'], $config['spam']['hidden_inputs_max']); $hidden_input_names_x = 0; for($x = 0; $x < $input_count ; $x++) { if($hidden_input_names_x === false || rand(0, 2) == 0) { // Use an obscure name $name = $this->randomString(rand(10, 40)); } else { // Use a pre-defined confusing name $name = $config['spam']['hidden_input_names'][$hidden_input_names_x++]; if($hidden_input_names_x >= count($config['spam']['hidden_input_names'])) $hidden_input_names_x = false; } if(rand(0, 2) == 0) { // Value must be null $this->inputs[$name] = ''; } elseif(rand(0, 4) == 0) { // Numeric value $this->inputs[$name] = (string)rand(0, 100); } else { // Obscure value $this->inputs[$name] = $this->randomString(rand(5, 100)); } } } public function html($count = false) { $elements = array( '', '', '', '', '', '
', '', '', '' ); $html = ''; if($count == 0) { // all elements $inputs = array_slice($this->inputs, $this->index); } else { $inputs = array_slice($this->inputs, $this->index, $count); } $this->index += count($inputs); foreach($inputs as $name => $value) { $element = false; while(!$element) { $element = $elements[array_rand($elements)]; if(strpos($element, 'textarea') !== false && $value == '') { // There have been some issues with mobile web browsers and empty