Restricting node access by IP using taxonomy terms
danwassink - April 29, 2008 - 04:01
Hello all,
I would like to have restricted access to certain nodes by IP. I would tag these nodes by a taxonomy term. So if I tagged it 'Private', only people within a certain IP would have access to this node, and if I tagged it 'Public' everyone would have access to the node. Does this make sense?
Has anyone ever seen anything like this or does anyone have any suggestions?
Thanks!
Dan Wassink

progress?
did you ever find a way to do this?
thanks.
leslye james.
count me in for interest.
count me in for interest.
Follow up
I needed similar functionality, except I needed to only allow site registration to people from certain IP addresses. I ended up modifying the module "register_country" so that instead of pulling from the IP2CC module database of countries, I just added the allowed IPs into the actual script. It's not based on taxonomy, but the idea could be modified to fit.
/**
* Implementation of hook_user().
* Checks the user's IP Address on registration.
* If they are from one of the specified IPs, allow registration to continue.
* If not, then redirect to a designated page.
*/
function register_ip_user($op, &$edit, &$account, $category = NULL){
//Use first 9 characters of allowed IP addresses
$locations = array('##.##.###', '###.###.#');
switch ($op) {
case 'register':
$addr = $_SERVER['REMOTE_ADDR'];
$addr = substr($addr, 0, 9);
if (in_array($addr, $locations)) { /* okay */ }
// No, go to the error page.
else { drupal_goto('register_notice'); }
break; /* end of register */
} /* end of switch */
return array();
}