Project

General

Profile

Feature #19466 ยป use_filter.diff

Administrator Admin, 2008-10-16 10:51

View differences:

t3lib/class.t3lib_div.php (working copy)
* @return boolean True if $ip is either of IPv4 or IPv6 format.
*/
public static function validIP($ip) {
if (strpos($ip, ':') === false) {
return t3lib_div::validIPv4($ip);
} else {
return t3lib_div::validIPv6($ip);
}
return filter_var($ipaddr, FILTER_VALIDATE_IP);
}
/**
......
* @return boolean True if $ip is of IPv4 format.
*/
public static function validIPv4($ip) {
$parts = explode('.', $ip);
if (count($parts)==4 &&
t3lib_div::testInt($parts[0]) && $parts[0]>=1 && $parts[0]<256 &&
t3lib_div::testInt($parts[1]) && $parts[0]>=0 && $parts[0]<256 &&
t3lib_div::testInt($parts[2]) && $parts[0]>=0 && $parts[0]<256 &&
t3lib_div::testInt($parts[3]) && $parts[0]>=0 && $parts[0]<256) {
return true;
} else {
return false;
}
return filter_var($ipaddr, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
}
/**
......
* @return boolean True if $ip is of IPv6 format.
*/
public static function validIPv6($ip) {
$uppercaseIP = strtoupper($ip);
$regex = '/^(';
$regex.= '(([\dA-F]{1,4}:){7}[\dA-F]{1,4})|';
$regex.= '(([\dA-F]{1,4}){1}::([\dA-F]{1,4}:){1,5}[\dA-F]{1,4})|';
$regex.= '(([\dA-F]{1,4}:){2}:([\dA-F]{1,4}:){1,4}[\dA-F]{1,4})|';
$regex.= '(([\dA-F]{1,4}:){3}:([\dA-F]{1,4}:){1,3}[\dA-F]{1,4})|';
$regex.= '(([\dA-F]{1,4}:){4}:([\dA-F]{1,4}:){1,2}[\dA-F]{1,4})|';
$regex.= '(([\dA-F]{1,4}:){5}:([\dA-F]{1,4}:){0,1}[\dA-F]{1,4})|';
$regex.= '(::([\dA-F]{1,4}:){0,6}[\dA-F]{1,4})';
$regex.= ')$/';
return preg_match($regex, $uppercaseIP) ? true : false;
return filter_var($ipaddr, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6);
}
/**
......
* @return boolean Returns true if the $email address (input string) is valid; Has a "@", domain name with at least one period and only allowed a-z characters.
*/
public static function validEmail($email) {
$email = trim ($email);
if (strpos($email,' ') !== false) {
return false;
}
return ereg('^[A-Za-z0-9\._-]+[@][A-Za-z0-9\._-]+[\.].[A-Za-z0-9]+$',$email) ? TRUE : FALSE;
return filter_var(trim($email), FILTER_VALIDATE_EMAIL);
}
/**
* Checking syntax of input url
*
* @param string Input string to evaluate
* @return boolean Returns true if the $url is valid;
*/
public static function validUrl($url) {
return filter_var(trim($url), FILTER_VALIDATE_URL);
}
/**
* cleans a given url
*
* @param string Input string to evaluate
* @return boolean Returns the $url cleaned (removed invalid chars);
*/
public static function cleanUrl($url) {
return filter_var(trim($url), FILTER_SANITIZE_URL);
}
/**
* Checks if current e-mail sending method does not accept recipient/sender name
* in a call to PHP mail() function. Windows version of mail() and mini_sendmail
* program are known not to process such input correctly and they cause SMTP
    (1-1/1)