White list IP address for administrator access

I have an area on my site that I would like to provide access to only a few people. My code now only works with one IP address, but I would like to be able to add more.

Here is what I use:

$ipaddress = $_SERVER['REMOTE_ADDR']; if($ipaddress == '111.111.111.111') { //Action for allowed IP Addresses } else { //Action for all other IP Addresses echo 'You are not authorized here.'; echo "<br />IP Address: ".$_SERVER['REMOTE_ADDR']; exit; } 
0
source share
1 answer
 $whitelist = array('111.111.111.111', '111.111.111.112'); if (in_array($_SERVER['REMOTE_ADDR'], $whitelist)) { //Action for allowed IP Addresses } else { //Action for all other IP Addresses echo 'You are not authorized here.'; echo "<br />IP Address: ".$_SERVER['REMOTE_ADDR']; exit; } 
+10
source

All Articles