Display/hide content from a specific IP address within a page

PLEASE NOTE These snippets are user submitted. Use at your own risk. For users who have setup drupal using an alternate database to the default (MYSQL), please note that the snippets may contain some database queries specific to MYSQL.

<?php
/**
* this Snippet allows you to display content ONLY to a visitor from
* a specific IP addresses in a page.
*
* Change the $allowed value to the IP address you want.
*
* This works with drupal 4.5 and drupal 4.6
*/
$allowed  = '100.100.100.100';
$userip = $_SERVER['REMOTE_ADDR'];
if(
$userip == $allowed){
    print
"This content can only be viewed by the IP address you specify.";
}
?>

To reverse the situation and HIDE content to a user from a specific IP address

<?php
/**
* this Snippet allows you to hide content from a visitor at
* a specific IP addresses.
*
* Change the $hidden value to the IP address you want.
*
* This works with drupal 4.5 and drupal 4.6
*/
$hidden  = '100.100.100.100';
$userip = $_SERVER['REMOTE_ADDR'];
if(
$userip != $hidden){
    print
"This content is displayed to everyone except the person from the IP address you specify.";
}
?>

 
 

Drupal is a registered trademark of Dries Buytaert.