Renan Ferreira
Renan Ferreira

Reputation: 2150

Limit access to only one wifi network

I'm building a small aplication that need to be running in just one place. So a need to limit de access to the file only to that wifi network. In this code I'm using IP for the purpose, but I don't really think that's de best practice, because the IP can change.

<?php
$externalIP = $_SERVER['REMOTE_ADDR'];
if($externalIP=="KNOWN IP") echo"YOU HAVE ACCESS";
else echo"YOU DON'T HAVE ACCESS";
?>

Upvotes: 1

Views: 353

Answers (1)

Daniel Figueroa
Daniel Figueroa

Reputation: 10676

If you're using a ordinary router you most probably have a network with local IP's that start with 192.168.1.xxx. That means that in theory you have 200+ of available IP's (this is probably limited by your router to a lower number). Now if your server is connected on the same network then your solution is not bad. What you could do is then to extract the three last digits in the IP address, and check if they are in the range of the allowed IP addresses. You still have to check if the three first fields are correct also of course.

If on the other hand the server isn't on the same network then it gets alot trickier, because then you have no way of knowing if the client is on wifi or not.

Most routers are configureable via a webbased interface, and if the router isn't completely sh*t you'll be able to see and set the range for wifi ip's (that is which address the router will assign via DHCP).

Upvotes: 1

Related Questions