Jacob Stetser
05-14-1999, 09:14 PM
<?
$headers = getallheaders();
while (list($header, $value) = each($headers)) {
[nbsp][nbsp] if($header=='Host' && $value=='www.yourdomain.com') {
[nbsp][nbsp][nbsp][nbsp]$filename="/path/to/index.html";
[nbsp][nbsp][nbsp][nbsp]$fp=fopen($filename,"r");
[nbsp][nbsp][nbsp][nbsp]$contents = fread( $fp, filesize( $filename ) );[nbsp][nbsp]
[nbsp][nbsp][nbsp][nbsp]echo[nbsp][nbsp]$contents;
[nbsp][nbsp] } elseif($header=='Host' && $value=='subdomain.yourdomain.com') {
[nbsp][nbsp][nbsp][nbsp]$filename="path/to/your/subdomain/index.html"
[nbsp][nbsp][nbsp][nbsp]$fp=fopen($filename,"r");
[nbsp][nbsp][nbsp][nbsp]$contents = fread( $fp, filesize( $filename ) );[nbsp][nbsp]
[nbsp][nbsp][nbsp][nbsp]echo[nbsp][nbsp]$contents;
[nbsp][nbsp] }
}
?>
What this does is look at the HTTP Request Header Host: and see what domain name people used to access your site. Make this your index page, etc and set everything up correctly, and you'll be able to serve different home pages to people depending on which subdomain they access!
Okay, so maybe it's not as cool as I hoped, and there's no error checking in this snippet.. but if you have www.yourdomain.com and sub.yourdomain.com pointing at the same page, now you can have viewers see different pages without any extra work on Terra's part :)
Any questions, comments, suggestions? This is just a piece of code I threw together as I try to learn more PHP..
If you want to see it at work, try
http://sandbox.icongarden.com/ vs. http://www.icongarden.com/sandbox/. Never mind the 404 page- that's simply the page I offered up for people trying to access the sandbox through the subdirectory method, see?
------------------
http://icongarden.com/?fq[nbsp][nbsp]
icongarden: making good ideas grow.
<!-- NO_AUTO_LINK -->
[This message has been edited by Jacob Stetser (edited 05-14-99)]
$headers = getallheaders();
while (list($header, $value) = each($headers)) {
[nbsp][nbsp] if($header=='Host' && $value=='www.yourdomain.com') {
[nbsp][nbsp][nbsp][nbsp]$filename="/path/to/index.html";
[nbsp][nbsp][nbsp][nbsp]$fp=fopen($filename,"r");
[nbsp][nbsp][nbsp][nbsp]$contents = fread( $fp, filesize( $filename ) );[nbsp][nbsp]
[nbsp][nbsp][nbsp][nbsp]echo[nbsp][nbsp]$contents;
[nbsp][nbsp] } elseif($header=='Host' && $value=='subdomain.yourdomain.com') {
[nbsp][nbsp][nbsp][nbsp]$filename="path/to/your/subdomain/index.html"
[nbsp][nbsp][nbsp][nbsp]$fp=fopen($filename,"r");
[nbsp][nbsp][nbsp][nbsp]$contents = fread( $fp, filesize( $filename ) );[nbsp][nbsp]
[nbsp][nbsp][nbsp][nbsp]echo[nbsp][nbsp]$contents;
[nbsp][nbsp] }
}
?>
What this does is look at the HTTP Request Header Host: and see what domain name people used to access your site. Make this your index page, etc and set everything up correctly, and you'll be able to serve different home pages to people depending on which subdomain they access!
Okay, so maybe it's not as cool as I hoped, and there's no error checking in this snippet.. but if you have www.yourdomain.com and sub.yourdomain.com pointing at the same page, now you can have viewers see different pages without any extra work on Terra's part :)
Any questions, comments, suggestions? This is just a piece of code I threw together as I try to learn more PHP..
If you want to see it at work, try
http://sandbox.icongarden.com/ vs. http://www.icongarden.com/sandbox/. Never mind the 404 page- that's simply the page I offered up for people trying to access the sandbox through the subdirectory method, see?
------------------
http://icongarden.com/?fq[nbsp][nbsp]
icongarden: making good ideas grow.
<!-- NO_AUTO_LINK -->
[This message has been edited by Jacob Stetser (edited 05-14-99)]