Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- public function valid_ip($ip, $which = '')
- {
- $which = strtolower($which);
- // First check if filter_var is available
- if (is_callable('filter_var'))
- {
- switch ($which) {
- case 'ipv4':
- $flag = FILTER_FLAG_IPV4;
- break;
- case 'ipv6':
- $flag = FILTER_FLAG_IPV6;
- break;
- default:
- $flag = array();
- break;
- }
- return (bool) filter_var($ip, FILTER_VALIDATE_IP, $flag);
- }
- if ($which !== 'ipv6' && $which !== 'ipv4')
- {
- if (strpos($ip, ':') !== FALSE)
- {
- $which = 'ipv6';
- }
- elseif (strpos($ip, '.') !== FALSE)
- {
- $which = 'ipv4';
- }
- else
- {
- return FALSE;
- }
- }
- $func = '_valid_'.$which;
- return $this->$func($ip);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement