开发者

PHP: allow only two IP addresses at the same time

I want my website to be accessed from only two IP addresses. whe开发者_运维技巧n ever the site is accessed by more than 2 IP addresses it will shoe an error. can any body done this in php please help me

thank you


Try

if($_SERVER['REMOTE_ADDR'] != '212.100.232.111' && $_SERVER['REMOTE_ADDR'] != '212.100.232.112'){
 die('No access');
}


If you want to restrict all visitors to certain IPs, the easiest/fastest way would be doing so in your web server, e.g. with an Apache .htaccess, instead of doing it in PHP:

Order Deny,Allow
Deny From All
Allow From 1.2.3.4
Allow From 5.6.7.8


To restrict the number of concurrent users you need some kind of sessions stored in a database. Then, when a new user logs in, check if there are already two sessions from different ips and in this case throw an error.

Note that you MUST make sessions expire quickly if someone is inactive so he doesn't prevent someone else from logging in just because he did not logout.


Use $_SERVER['REMOTE_ADDR'] to get the address of the incoming connection, and test against it to perform the appropriate redirection or what have you.


You need to use the $_SERVER['REMOTE_ADDR'] superglobal variable: this should give you the IP address from which the client's request originated. Just test to see whether it's allowed and show your error message if not.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜