Forum Moderators: coopster

Message Too Old, No Replies

Using $_SERVER['HTTP_HOST'] to host multiple domains with same files

         

Nutter

9:36 pm on Jun 17, 2005 (gmt 0)

10+ Year Member



I'm looking at setting up a web application that will allow users to have their own domain, but hosted by me. The backend will by PHP and I don't want to have to upload the same code to a different folder for each account so what I'm thinking is to have every domain pointed to the same folder in httpd.conf and then use $_SERVER['HTTP_HOST'] to determine which settings to use. Before I spend a lot of time and possibly money doing this, are there any pitfalls that I'm missing? I don't want to get a month in before I realize that half of the potential visitors are not seeing the pages as expected.

Thanks,
- Ryan

globalissa

9:54 am on Jun 18, 2005 (gmt 0)

10+ Year Member



Perhaps this reply is not the answer you expected, but
the question I would have is ... do the customers want to display their own header and footer in the application, and or how many customers will want custom modifications, if any, and will you be capable of handling customizations and if so how?

However, in general - given that you are the host - it is preferable to keep only one application where possible to optimize your time investment.

Globalissa

hakre

10:10 am on Jun 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hi nutter,

what you want to do seems very strange to me. please don't feel offended but it looks like you want to re-invent the wheel again. one of the most efforts done in server development over the last years were to make shared hosting possible, comfortable and secure. thats to host multiple domains and users on one box. this is done today by quite each hoster putting up to 1000 users on one box. the software taken for this varies, but most often this is *nix with apache (including, but not limited to: php, mysql, ssh etc. pp.).

*nix itself is a multi user OS so i would start on the OS basis before taking php into account to manage multiple user on a system (incl. domain names)

my 2 cents,
hakre

dmorison

10:25 am on Jun 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ryan,

There shouldn't be any problem with the aproach that you describe. I am about to implement a white label affiliate offering for one of the web services that I host and intend to do exactly the same.

Even if, as globalissa points out, some of your clients want custom header / footer code this can still be implemented within the single codebase with custom code pulled in if it exists for the current $_SERVER['HTTP_HOST'].

It is extremely unlikely these days that HTTP_HOST would not be set. In theory, it does require a HTTP1.1 connection from the client, but in practice most HTTP1.0 devices implement the HOST header from the 1.1 protocol. That said, you should still be prepared to handle the situation in which HTTP_HOST is empty.

anshul

10:54 am on Jun 18, 2005 (gmt 0)

10+ Year Member



Hi there,

Before I spend a lot of time and possibly money doing this, are there any pitfalls that I'm missing? << Only pitfall I guess is little annoyance of search engines.

I've recently done this; $_SERVER['HTTP_HOST'], I think is always available, and if not ( God knows! ), you can fix it server-side.

I used array to store a list of configuartion variables based on $_SERVER['HTTP_HOST'] and present different content from same files, when domain name is switched. I checked in all the browsers. I also set default settings if I don't get $_SERVER['HTTP_HOST'] and switch the system to default behaviour.

Assumed: all the domains point to a directory in your main domain name account.

Nutter

3:53 pm on Jun 19, 2005 (gmt 0)

10+ Year Member



The idea is that the application is the same, but the data will be different, and in differing styles.

This is not what I'm writing it for, but this is a good example of the concept...

Teachers set up accounts where they can post information about their classes. There is a homework section, a notes section, an upcoming assignments section, and a forum so students can discuss the work. Ms. Smith has the domain mssmithforenglish.com and Mr. Davis has davisthesciencegeek.com. Ms. Smith wants her site calm and relaxing and girly. Mr. Davis wants his to be more hi-tech looking. So, they each pick from the available styles to match what they're after. But the backend code is the same regardless. The sites still have the same basic functions, but different layouts and different data.

The problem is that I don't want to have to update dozens (hundreds hopefully :-) ) of different directories when I find a bug. I supposed it would be a pretty easy script to copy one directory to all subfolders of another, but it's an unnecessary step.

After reading about http 1.0 and not officially sending the http_host field, I started thinking of other options. I think what I may do is have an index.php with -
<?php
$domain = "mssmithforenglish.com";
include('/a/file/from/different/folder.php');
?>

This would seem to fix the problem of http_host, even if it is a fairly rare issue.

dmorison

4:05 pm on Jun 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ryan,

I think you may be worrying about nothing here (perhaps my fault for rasing the issue), as unless you are planning on using a separate IP address for each site then I think you are already relying on the HTTP HOST header, as this is the only way that Apache can support name based virtual hosts...

Nutter

4:19 pm on Jun 19, 2005 (gmt 0)

10+ Year Member



:-) - You're right.

I was focused on the PHP part of this, I didn't even think about the name hosting. Thanks for that.