I want my website to be accessed from only two IP addresses. when 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
I want my website to be accessed from only two IP addresses. when 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
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.
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.