How to make a page available only for certain ip's

Tagged:  

How to make a page available only for certain ip's
How to block a php page for everyone except for certain ip's
How to only let certain ip's access a page and redirect the others somewhere else in php
 
You can do that like this
<?php if (($_SERVER['REMOTE_ADDR']<>'79.114.167.66')&&($_SERVER['REMOTE_ADDR']<>'78.97.250.137')) die ('the site is in maintenance');
?>
This means if your ip is not 82.00.00.164 or 82.11.11.52 stop the script. If it's placed at the begining of the script, a blank page will be presented to the user.
You could also redirect them somewhere else:
<?php if (($_SERVER['REMOTE_ADDR']<>'87.77.00.100')&&($_SERVER['REMOTE_ADDR']<>'81.11.167.52'))exit (header('Location: http://www.example.com')); ?>
 
A user that doesn't have one of those ip's will be redirected to example.com. I used this when i was working on a site that was already live, at work, after a deploy, to do a final test before live; It's also usefull when I work on a site online and i need to show things to a customer.