views:

20

answers:

1

Hi

I have several domains, only one website and one databse table for each domain.

example: wbesite.us - data from USA goes to database table main_usa wbesite.co.uk - data form UK goes to database table main_uk

Only have one database with name of the website.

Having only one website structured, and having variables like

$sql="select * from main_".$countrycode." where bla..bla..., and many other variables to catch the domain extension, and so on...

Now, instead of having one full website for each domain, how can set a script and wher do I put it in order to detect the domain that the user uses.

In my server root do I create something like website.$domain ?

Something like website OLX but for different purposes.

I hope I made myself clear.

Thank you.

A: 

You could use the $_SERVER['SERVER_NAME'] global and somehow parse it, to get the country code.

I didn't try it, but something like this should work:

$servername_array = explode('.', $_SERVER['SERVER_NAME']);
$country_code = array_pop($servername_array);

That way, $country_code will be com, uk, or whatever is after the last dot in the domain name.

oli
Ok thaks. But were do I right it? In the index.php? If so, wich name of the folder that has the website called? Will be in the server root? usualy the folders were the website are has the name of the website with the extension like website.us or website.co.uk I hope you follow me. thanks
jose silva
If you really only need one website, I would place it in one of the folders, for example website.us. The other domains could point to this one, too, this way if you need to change anything, you only have to do it on one file. Read up on .htaccess files. I don't know the file system of your site, but you could put my code in a function, then include it in every file where you need the country code.
oli
Good idea. I will follow your tip. Iwill let you know if it works. Thanks a lot
jose silva