Sort of a solution for people with a dynamic IP...

The problem

You have a dynamic IP but telling people to go to just plain sucks. You also have lots of domains (like we all do) and might want to use them ( instead.

Why would I want such a thing?

Sometimes, you want people to be able to access some services like HTTP of your computer but that's it. No sniffing around, no... nothing! But giving them your IP might trigger stupid things. Men are stupid by design.

And what's the... uh... solution?

Not long ago, a customer wanted a subdomainservice, so I wrote a really dirty combination of some scripts which I want to publish here. They are an initial subdomain-creator, a script to update a subdomain's IP, a .htaccess and an index.php to do the rewriting.

[an error occurred while processing this directive]

The .htaccess

RewriteEngine On
RewriteRule !^index.php /index.php%{REQUEST_URI} [L]

The index.php


$sDomain = ""
$sSub = substr($_SERVER["HTTP_HOST"], 0, -(strlen($sDomain)+1));

$oDB = dbmopen("/path/to/dbm/subdomains.db", "r");
$sTarget = dbmfetch($oDB, $sSub); 

if ( $sTarget ) {
  list($sTarget, $sPassword) = split(" ", $sTarget);

echo("Subdomain ".$_SERVER["HTTP_HOST"]." not defined yet");


A sample file

mark    markspass
frank  frankspassword
jack   yeahandjacks

A sample converter to get your subdomain.db created out of the


$oMap = fopen("/path/to/dbm/", "r");
$oDB = dbmopen("/path/to/dbm/subdomains.db", "n");
while ($sLine = fgets($oMap)) {
  list($sKey, $sValue, $sPassword) = preg_split("/\s+/", $sLine);
  echo("Inserting $sKey:$sValue<br>\n");
  dbminsert($oDB, $sKey, "$sValue $sPassword");


A possible script to call when the IP has changed:


$oDB = dbmopen("/path/to/dbm/subdomains.db", "rw");
$sTarget = dbmfetch($oDB, $_REQUEST["subdomain"]); 

if ( !$sTarget ) {
  sleep 10;
list($sTarget, $sPassword) = split(" ", $sTarget);
if ( $_REQUEST["password"] != $sPassword ) {
  sleep 10;
dbmreplace($oDB, $_REQUEST["subdomain"],
               ? (preg_match("/http:\/\//", $_REQUEST["url"])
                   ? $_REQUEST["url"]
                   : "http://".$_REQUEST["url"])
               : "http://".$_SERVER["REMOTE_ADDR"]).
           " $sPassword");
echo("Changes successful.<br>");


Last modified: 26.07.2006 [01:38:23]