Skip links

Introduction, attempt two + a Drupal tip

Wow. So I introduced MyCommunity.org yesterday, and I wondered why nobody bothered to sign up.

It randomly came up with my sister today. "Is it a site yet?!", she asked. Duh, I thought, just check the site to find out.

But then I realized I had forgotten to remove the access restrictions on the site, so everyone other than me was in fact seeing nothing but the logo!

So here's another introduction. Go create a place for your community to talk, share, and connect.

For bearing with me, I offer up the cause of my blunder as a Drupal tip.

Say you want to have your visitors see a simple page, letting them know your service is coming soon or whatever. Sure, you could take the site offline under Site maintenance in admin/settings, but Drupal doesn't allow you to do much with that page, plus it gets in the way when you're trying to test your site as different users and such.

Instead, create a regular HTML page like index.html with whatever you want on it.

Next, add the following code at the very top of your theme's page.tpl.php file:

<?php
global $user;
$your_ip = '66.77.88.999';
if ($_SERVER['REMOTE_ADDR'] != $your_ip) {
if (!$user->uid && arg(0) != 'user') {
header('location:/index.html');
}
}?>

Of course, replace the IP address and custom page with your own. Here's what happens: if the visitor originates from an IP address that is not yours we want to show the custom page, but first check to make sure they're not logged in (if they are, we can assume they're authorized, and this lets me log in from elsewhere too) and that they're not *trying* to log in (if they're trying to go to user/*, we want to show the login page, and again this ensures I can log in from elsewhere). So if a remote visitor is not logged in nor trying to log in, show your custom page instead. Phew, thankfully code itself ain't that verbose! Of course, don't do what I did and forget to remove that code when you want to go live!

Thanks for your interest, and your thoughts.

Updated for clarity.