Restrict website access, while developing your site locally and keeping your client up to date can be tricky
When you are developing a website, especially when the client has a live website on a domain, you may be in a position where you are developing your site locally and now need the client to view it, but not Joe Public.
So how do you restrict access to a website. In my example i use a WordPress website. The principle is the same for any website The goal, so only your chosen client can access the new website area .
2 simple ways to restrict website access to development area
Both bits of code will need to go in your public_html (or equivalent) folder’s index.php file just below the “<?php” (probably line 2)
- Option 1 you will need their IP address and your IP address
- Option 2 they visit a URL and it sets a cookie

Option 1 : Restricted IP Address
you will need their IP address and your IP address. You can add as many IP addresses in as you would like just put them in apostrophes and separate with a comma.
if (!in_array($_SERVER['REMOTE_
ADDR'], array('YOUR.IP.HERE', 'THEIR.IP.HERE'))) {
header("Location: http://where-you-want-to-send-visitors.co.uk/page");
exit;
}
Option 2 : Set a Cookie
The client will need to go to the site and put “?hello” in the URL once to set the cookie and then they can use the site as normal
if (!isset($_COOKIE['hello']) && !isset($_GET['hello'])) {
header("Location: http://where-you-want-to-send-visitors.co.uk/page");
exit;
}
if (isset($_GET['hello'])) {
setcookie('dev', 'dev', time()+50000);
} That’s it, you should now be able to grant them access to your developed site. Let me know if this worked for you and helped you restrict website access during your web site development.


