Reputation: 197
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 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
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 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.
Upvotes: 0
Views: 747
Reputation: 1252
As we discussed in our chat, below is a sample code to give you an idea on how to perform your checks.:
$checkip = $_SERVER['Something with IP'];
$validate = '';
if($checkip == $_SERVER['Some IPv4'])
{
$ip = the IPv4 address
$validate = 4;
}
else
{
$ip = the ipv6 IP
$validate = 6;
}
if($validate == 4)
{
$ip = echo substr($ip, 0, ???); // IPv4 address
}
else
{
$ip = substr($ip, 0, 15); // 2000:950:ac2:3
}
Again: this is just to give you an idea. You need to create your own function to use this correctly. I suggest to make this a function at the login, and give variables to your function. So you do not have to modify your script for other companies, only the variables your are sending. (function could simply return true
or false
;
Good luck man!
Upvotes: -1