I want to restrict access to users who are not connected to one of the WIFI's of a specific company. So for instance, we have a company and this company has 2 different WIFI networks to connect. I want to only give access to a page if the client is connected by one of these WIFI's.
- The IPv4 of one of the WIFI's is for instance: 123.45.65.101
- The IPv6 of the other WIFI is for instance: 2000:980:ce5:1:4dd9:47ad:ff9b:4454
The following PHP script worked perfectly in time there was only a IPv4 address:
if(!in_array($_SERVER['REMOTE_ADDR'], $ip_adres_allow) && !in_array($_SERVER["HTTP_X_FORWARDED_FOR"], $ip_adres_allow)) {
die("You can't access this webpage, please try again by your employee.");
exit();
}
Where $ip_adres_allow -> array of values stored in database
My questions are:
I know IPv4 addresses are the same per WIFI, they wont change. But is a IPv6 address the same? I've tracked some IPv6 addresses from the company and they like to seem to start with 2000:980:ce5:1:XXXX:XXXX:XXXX:XXXX. (whereas the X's are not the same) Does this mean a WIFI has a range of IPv6?
- Is 2000:980:ce5:1:4dd9:47ad:ff9b:4454 the same WIFI as 2000:980:ce5:1:55de:de7d:df6e:ea62 for instance? Or is this DEFINITELY SURE that it is another WIFI network?
Is there a way to modify the PHP script above to check if a client is connected to one of the WIFI's? Or should this script still work? Because the database is hardcoded with IPv6 and IPv4 addresses. And if IPv6 is one address, there might be someone that is connected to the WIFI but can't access the page because it is not an exact match of the value in the database.
Please correct me if im wrong.
Thanks for reading.
FILTER_VALIDATE_IP
andFILTER_FLAG_IPV6
be useful for you? AND this might be useful: (inet_pton) php.net/manual/en/function.inet-pton.php – Ronnie Oosting2000:980:ce5:1:XXXX:XXXX:XXXX:XXXX
, so if IP starts with2000:980:ce5:1
, you can do your code. Would that be a solution? ip's can change unless its static. So, this means also for ipv6. Just wondering if that beginning is always the same. If that is the case, I would have done like I explained. Would that solve your issue? – Ronnie Oosting