function isSuspect($value, $pattern, &$suspect) { if (is_array($value)) { foreach ($value as $item) { isSuspect($item, $pattern, $suspect); } } else { if (preg_match($pattern, $value)) { $suspect = true; } } }
function isSuspect($val, $pattern, &$suspect) { if (is_array($val)) { foreach ($val as $item) { isSuspect($item, $pattern, $suspect); } } else { // If the pattern matches, set $suspect to true. if (preg_match($pattern, $val)) { $suspect = true; } } }
function isSuspect($val, $pattern, &$suspect) { if (is_array($val)) { foreach ($val as $item) { isSuspect($item, $pattern, $suspect); } } else { // if one of the suspect phrases is found, set Boolean to true if (preg_match($pattern, $val)) { $suspect = true; } } }
function isSuspect($val, $pattern, &$suspect) { //if the variable is an array, loop through each element //and pass it recursively back to the same function if (is_array($val)) { foreach ($val as $item) { isSuspect($item, $pattern, $suspect); } } else { //if one of the suspect phrases is found, set Boolean to true if (preg_match($pattern, $val)) { $suspect = true; } } }
<?php $m_missing = ""; $mail_error = ""; $c_values = array('email' => '', 'subject' => '', 'message' => ''); extract($c_values); if (isset($_POST['contactus'])) { $suspect = false; $pattern = '/Content-Type:|Bcc:|Cc:/i'; function isSuspect($val, $pattern, &$suspect) { foreach ($val as $item) { $suspect = preg_match($pattern, $item) ? true : false; } } isSuspect($_POST, $pattern, $suspect); if (!$suspect) { foreach ($_POST as $key => $value) { $value = pure_it($value); empty($value) ? $m_missing = "Please fill out all the fileds." : (${$key} = $value); } } $headers = ""; if (!$suspect && !empty($email)) { $validemail = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL); if ($validemail) { $headers .= "From: {$validemail}\r\n"; } else { $mail_error = "Invalid email address!"; } }