This is a useful script to add at the start of any PHP file which you want hidden from a specific IP address or addresses. Anything below this first script will be hidden from anyone listed in the $valid_ips array.

$valid_ips = array('123.123.123.123','32.23.13.31','123.45.678.90');
if (in_array($_SERVER['REMOTE_ADDR'],$valid_ips)) {
   echo "You do not have permission to access this website";
   exit();
}

PHP: Grant access based on Client IP

The opposite requires a simple exclamation mark before in_array() to change the script so that only those listed in the array will be allowed to see the site. Anything below this code will only be accessible IPs is in the array.

$valid_ips = array('123.123.123.123','32.23.13.31','123.45.678.90');
if (!in_array($_SERVER['REMOTE_ADDR'],$valid_ips)) {
   echo "You do not have permission to access this website";
   exit();
}

Hello, I'm Keith, a website developer in Belfast, Northern Ireland working with PHP, Magento, Shopify, WordPress along with everything that involves getting websites online

keithgreer.uk · Blog Posts
 page.title

Warning: Your browser is very out-of-date. You should upgrade to a better browser.