Hi everyone,
I am trying to create a code where I want to allow or deny certain host names and/or IP-addresses to be allowed to execute a code within an if-statement.
The problem is that I am not quite sure how I can accomplish this in coding.
If I have a variable that looks like this:
$allowed_hosts = "127.0.0.1|cmt|192.169.|169..121.";
Then I want the following to be allowed to access and run the code:
- 127.0.0.1
- cmt ( is a wildcard, as long as the hostname starts on cmt it should be allowed access)
- 192.169.* (all IP's that starts with 192.169 are allowed access)
- 169..121. (all IP's according to: 169.(0-255).121.(0-255) should be allowed)
Now... How can I solve this with a good looking code snippet which doesn't take too long to run?
What I did so far is to get the variable ´$allowed_hosts´ in to an array by exploding it using the following code:
$allowed_hosts_array = explode('|', $allowed_hosts);
Thank you in advance for all your help!