仅允许从特定网络访问网站
我正在制作一个对我学校的学生有吸引力的网站。我只想在用户使用校园 WiFi 或硬线时才允许访问。使用 PHP,我如何限制我确定在校园互联网上的人员的访问?
I'm making a website that appeals to students at my school. I want to only allow access if the user is on the campus wifi or hardwire. Using PHP, how can I restrict access to people I am sure are on the campus internet?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您需要获取一系列 IP 地址并将它们放入一个时间列表中。然后,您可以使用 $_SERVER['REMOTE_ADDR'] 变量来检查访问白名单。在页面的开头执行如下操作:
You would need to get a range of IP addresses and put them in a while list. You could then use the $_SERVER['REMOTE_ADDR'] variable to check against the white list for access. Do it at the beginning of the page with something like this:
这通常在网络服务器配置中完成,其优点是也适用于图像,但理论上您可以放入
每个 PHP 页面。
This is usually done in the webserver configuration, which has the advantage of also working for images, but in theory you could put
in every of your PHP pages.
首先,您需要从学校的网络管理员处获取IP范围。
然后从 PHP:
现在编写 inRange($ip) 函数,如果给定的 ip 在范围内,则返回 true。你可以使用explode函数来获取ip的各个部分来进行比较..:)
At first, you need to get the range of IPs from your school's network admin.
Then from PHP:
Now write inRange($ip) function to return true if the given ip is in the range. you can use explode function to get pieces of the ip to compare.. :)
已经提到过,但“正确”的方法是在网络服务器的设置中指定 IP 范围(IOW,不要在 PHP 中这样做)
It's already been mentioned, but the 'right' way to do it is to specify the IP range in the setup of your webserver (IOW, don't do it in PHP)