This is a code snippet to keep unwanted visitors out while a site is under construction or being updated. The associative array helps to keep record of the identity of the user’s IP instead of just a collection of numbers with no semantic association. The $filter_ips value makes it easy to toggle the filtering on/off.
<?php // --- Filter vitsitor's IP address and bounce those not in the list. $bounce_url = '/maintenance.php'; $filter_ips = true; $allow_ips = array ( 'ORG: Firstname Lastname' => '00.00.00.00' ); if ( $filter_ips && !in_array ( $_SERVER[ 'REMOTE_ADDR' ], $allow_ips ) ) { header ( "location: $bounce_url" ); exit (); } ?>
It’s also helpful to output the user’s IP address on your bounce page so user’s trying to gain access can easily copy/paste their IP to send to you:
<?php echo $_SERVER[ 'REMOTE_ADDR' ]; ?>