Building Rock Solid Websites

.

Blogs

Hidden pages in Drupal

My client had a need for hiding a page from the general public, yet keeping the permissions to anonymous, so that they could have a specific referer, and industry publication, link to this page to offer in-store specials only available through that publication.

So this is how I accomplished that on D6:

With CCK, create a new content type, called (euphemistically) Secure Page. Give it a new field, called referrerip.

Then create a new TPL, called node-secure_page.tpl.php.

Inside this:

$remoteadd = $_SERVER['HTTP_REFERER'];
//get the field data
$field = $node->field_referrerip[0]['value'];
global $user;

// Check to see if $user has the administrator role. NOTE: the role needs to be in the system, and the user 1 assigned that role
if (in_array('Admin', array_values($user->roles))) {
$usercheck = TRUE;
}

if(strpos($remoteadd,$field) || $usercheck){ //the user check helps you to write/view the page inside drupal without restriction

print $content;

} else {
print '

This page is not available from your location.

';
}
?>

Now create a new Secure Page, and in the referrerip field just add the desired referrer, either by IP, or domain, or page name.