Reputation: 1
I want to create a directory page for my company's website that is only accessible from my company's network. I know I can IP restrict the entire site, but I just want to do one page. I've searched around for plugins and code solutions, but I've come up empty. Is it possible?
Upvotes: 0
Views: 1357
Reputation: 497
A rather late answer, but two solutions:
(1) You can create a new template (possibly by cloning an existing page template), and choose that template for the page you want to protect. You can then add in PHP code to the template, so that the_content() is only visible to people within a certain IP range.
(2) You can create a function in functions.php that says if the page has a certain ID, it is only visible to people within a certain IP range.
For example, for (1):
//Get the user's IP
$usersIP = $_SERVER['REMOTE_ADDR'];
//Convert it into a string
$usersIPlong = ip2long($usersIP);
//Get strings for the upper and lower bounds of acceptable IPs
$highIP = ip2long('111.1.11.255');
$lowIP = ip2long('111.1.111.0');
//And if the users IP is within that range...
if ($usersIPlong <= $highOIIip && $lowOIIip <= $usersIPlong){
//show the page content
the_content();
}
else {
echo "Bugger off";
}
Upvotes: 1