0

This is a basic question.. I have been learning SQL php for just over a year. I am building a great database I would like to share with my customers on their own domain/server. So, they would actually log in to my domain to update info to their domains. This makes for community type data.

Would this work:

if($_SERVER[‘HTTP_HOST’] == “www.site1.com” {
$site_id = 1;
$site_css = ‘path/tosite1.css’;
$site_images = “path/to folder/for images/site1/”;
}
if($_SERVER[‘HTTP_HOST’] == “www.site2.com” {
$site_id = 2;
$site_css = ‘path/tosite2.css’;
$site_images = “path/to folder/for images/site2/”;
}

2 Answers2

1

A simpler method is to use webserver level aliases, e.g. for Apache, you'd have

<virtualhost example.com>
   Alias /css  /path/to/example.com/css/stuff/
   Alias /images /path/to/example.com/images/
</virtualhost>

<virtualhost otherexample.net>
   Alias /css  /path/to/otherexample.net/css/stuff/
   Alias /images /path/to/example.com/images/
</virtualhost>

and so on. Every site would have its own virtual css and images directory, which Apache will transparently map to the appropriate site-specific real directory. All your sites would simply have

<link type="text/css" rel="stylesheet" href="/css/whatever.css" />

and Apache will take care of figuring out which of the MANY whatever.css's you have on your multi-site server should really be used.

Marc B
  • 356,200
  • 43
  • 426
  • 500
  • In answer below by desbest suggests handling each one manually is not ideal; I should keep focus on opportunity to make this dynamic in future?? – Cloverlone Oct 03 '12 at 13:21
  • It'd depend on how often you're adding the sites. One a month, go for manual. dozens per day, go dynamic. – Marc B Oct 03 '12 at 15:04
0

This is a bad idea because your solution cannot scale past 100.

What happens if you're hosting 100 sites for people? You'll end up with a really long php file.

To remedy this, you can start storing your values in a mysql database. If you would like your php code to be practical, consult the Tizag mysql tutorials.

desbest
  • 4,746
  • 11
  • 51
  • 84
  • well,.. yes. I see what you are saying. Hold values in DB for .com, csspath, imagespath and use a query, .. where? I want a different css loaded upon domain name. SO does this query go in config file? – Cloverlone Oct 02 '12 at 22:02
  • if(isset($_SERVER[‘HTTP_HOST’] { $site = htmlspeicalcharacters($_SERVER[‘HTTP_HOST’]; } $q = ‘SELECT site_id, site_name, site_www, site_css, site_images FROM sites WHERE site_name = $site’; – Cloverlone Oct 02 '12 at 22:13
  • One question desbest, why not able to scale beyond 100? Just curious. – Cloverlone Oct 03 '12 at 13:23
  • And one more question, what is best way to test this feature on local server? – Cloverlone Oct 03 '12 at 13:40
  • With wampserver. Also that one answer on this page is good for numbered paths and is quick and simple, and the other one will take you longer to setup if you want to break out of your numerical ordering system for your paths. – desbest Oct 03 '12 at 17:07