Forum Moderators: coopster

Message Too Old, No Replies

Detecting which webhost I am using?

         

thing3b

10:07 pm on Nov 18, 2008 (gmt 0)

10+ Year Member



I have a custom PHP CMS that I use on a few websites hosted on different webhosts. The problem I have is that each webhost has different settings needed to connect to the database, etc. This means that for each webhost there needs to be a different config file to hold these settings.

The problem with a config file for each webhost is that I can not just run all webhosts off the same code-base.

What is the best way to detect which webhost the CMS is running on?

I was sort of thinking along the lines of:

If SERVER_NAME = a and IP = b THEN WEB_HOST = localhost
If SERVER_NAME = c and IP = d THEN WEB_HOST = x
If SERVER_NAME = e and IP = f THEN WEB_HOST = y
If SERVER_NAME = g and IP = h THEN WEB_HOST = z

I would then load the config file for WEB_HOST.

The problem with this is that I know IP addresses will change and break it all so that is not a good idea. I am not sure how often SERVER_NAME might change.

Any ideas?

willis1480

3:52 am on Nov 19, 2008 (gmt 0)

10+ Year Member



just test your connection and run through till you find one that works...ugly, but would work.

...or most hosts use a different directory structure.
Use $_SERVER['DOCUMENT_ROOT'] to test the directory structure. If each is unique you could use this.

...or use $_SERVER['SERVER_NAME'](aka mydomain.com)...you gotta know which host serves which site (not completely true). Then just check against an array in a config file or something to see how to connect.