Ok I have now solved this issue by using fnmatch (custom function for Win).
First of all, I create function ´fnmatch´ if it does not already exist (found in the manual page for this function).
if(!function_exists('fnmatch')) {
/** Create function ´fnmatch´ if not already exists (if runned on a Windows platform). */
function fnmatch($pattern, $string) {
/** Match string in var ´$string´ against pattern in var ´$pattern´ using regular expression.
* Returns True if string matches pattern, or False if not. */
return preg_match("#^".strtr(preg_quote($pattern, '#'), array('\*' => '.*', '\?' => '.'))."$#i", $string);
}
}
And then I also created this small function to check whether or not the given hostname or IP-address is valid or not:
function allowhost($hostname, $ipaddress, $allowed_host) {
/** Call function ´fnmatch´ to see if var ´$hostname´ and/or var ´$ipaddress´ matches the var ´$allowed_host´. */
if ((fnmatch($allowed_host, $hostname)) OR (fnmatch($allowed_host, $ipaddress))) {
return true;
}
else {
return false;
}
}
This is where I check the entire string of allowed hosts and IP-addresses (which may also contain wildcards):
/** Get string of allowed hostnames and IP-addresses from configuration
* directive ´CMS_internalnet´ in to array ´$cms_allowinternal. */
$cms_allowinternal = explode('|', $_CMSCONFIG['CMS_internalnet']);
/** Loop through each hostname and IP-address in array ´$cms_allowinternal´ and match
* them against the string of allowed hosts in var ´$cms_allowinternal´. */
foreach ($cms_allowinternal as $allowed_host) {
if (allowhost($client_hostname, $client_ipaddress, strtolower($allowed_host))) {
echo "Access granted.";
}
}
Thanks everyone for your superiour help!