/    Sign up×
Community /Pin to ProfileBookmark

mysite.$domain

Hi

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

example: wbesite.us – data goes to database table main_usa
wbesite.co.uk – data 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 ?

I hope I made myself clear.

Thank you.

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@SrWebDeveloperMar 17.2010 — Use $_SERVER['SERVER_NAME'] which is well supported on numerous web hosting platforms and create a switch or if/elseif/else in a top level script that sets the crucial variables used for database and so on, i.e.:

[code=php]

if ($_SERVER['SERVER_NAME'] == "site1.domain.ext") {

// Set variables for site1 here

}
else if ($_SERVER['SERVER_NAME'] == "site2.domain.ext") {

// Set variables for site2 here
}
else {

// Set variables for site3 or whatever

}
[/code]


Is this what you meant?

On a side note, in your code as posted you include two variables that are set in the user scope, not the global scope. So $countrycode and $domain don't mean anything to us. But using a switch or if/else if/else as detailed above, you could set $domain to be $_SERVER['SERVER_NAME'], but doing so is redundant, its more efficient to reference the global version directly. Otherwise if you have some need to copy it, I'd use a constant instead to ensure it can't be altered. Just food for thought.

-jim
Copy linkTweet thisAlerts:
@JoseSilvaauthorMar 17.2010 — Use $_SERVER['SERVER_NAME'] which is well supported on numerous web hosting platforms and create a switch or if/elseif/else in a top level script that sets the crucial variables used for database and so on, i.e.:

[code=php]

if ($_SERVER['SERVER_NAME'] == "site1.domain.ext") {

// Set variables for site1 here

}
else if ($_SERVER['SERVER_NAME'] == "site2.domain.ext") {

// Set variables for site2 here
}
else {

// Set variables for site3 or whatever

}
[/code]


Is this what you meant?

On a side note, in your code as posted you include two variables that are set in the user scope, not the global scope. So $countrycode and $domain don't mean anything to us. But using a switch or if/else if/else as detailed above, you could set $domain to be $_SERVER['SERVER_NAME'], but doing so is redundant, its more efficient to reference the global version directly. Otherwise if you have some need to copy it, I'd use a constant instead to ensure it can't be altered. Just food for thought.

-jim[/QUOTE]


Thank you jim.

It makes sense.

But now tel -me

In wich file and in wich website domain I include that script?

Do I have to have for example a website.net to add this into the index.php file or what?

Because I have two wqula copies of the website twice in the root directory. One called website.us another website.co.uk Of course I have two different database tables under the same name. one table is main_USA another is main_UK and I use in the query main_".countrycode." to make the data to be saved in the respective table.

Let see if you can help me more here.

thanks.
Copy linkTweet thisAlerts:
@SrWebDeveloperMar 18.2010 — Now we're getting into the web server and DNS setup. Warning: if you're unfamiliar with any of this, contact your webhost to do all the setup for you.

Those are unique top level domains, so the recommended approach (for proper SEO and easier web server logging setup) is to first set the DNS for each domain to point to your single web server IP, then setup a unique virtual host for each domain and pick one domain as the primary. In the secondary virtual host setup a redirect 301 back to the primary (or in it's document root use PHP's header command to do the 301 and location redirect). Thus a user browsing to your secondary domain will end up at your primary, their browser URL will change to the primary, and you can never reference the origin secondary domain in any of your scripts.

In your case, I think you want each domain to be distinct AND you apparently want to simplify things by consolidating two domains in one site and one set of scripts, if I follow you correctly. If so, noting the above approach as the defacto standard, I believe Apache does allow two virtual hosts to [U]share the same document root[/U]. So both web sites would serve the same index.php, and in that you could use $_SERVER['SERVER_NAME'] and so on as I discussed earlier. That's all I can think of at the moment.

-jim
Copy linkTweet thisAlerts:
@JoseSilvaauthorMar 18.2010 — Now we're getting into the web server and DNS setup. Warning: if you're unfamiliar with any of this, contact your webhost to do all the setup for you.

Those are unique top level domains, so the recommended approach (for proper SEO and easier web server logging setup) is to first set the DNS for each domain to point to your single web server IP, then setup a unique virtual host for each domain and pick one domain as the primary. In the secondary virtual host setup a redirect 301 back to the primary (or in it's document root use PHP's header command to do the 301 and location redirect). Thus a user browsing to your secondary domain will end up at your primary, their browser URL will change to the primary, and you can never reference the origin secondary domain in any of your scripts.

In your case, I think you want each domain to be distinct AND you apparently want to simplify things by consolidating two domains in one site and one set of scripts, if I follow you correctly. If so, noting the above approach as the defacto standard, I believe Apache does allow two virtual hosts to [U]share the same document root[/U]. So both web sites would serve the same index.php, and in that you could use $_SERVER['SERVER_NAME'] and so on as I discussed earlier. That's all I can think of at the moment.

-jim[/QUOTE]


Ok Jim

I will discusse that with my hosting people showing your taughts because it makes sense. but I don't have expertise for that. The only thing that I have done so far was creating alias point into the main web site, but all shows the same data. I will try first to use one domain lets say website.net (previously registered9 and create aliases with others changing variables in a call.php file seting the eay you have mention previously. I will let you know the outcame of that.

so far thanks a lot.

keep well
Copy linkTweet thisAlerts:
@SrWebDeveloperMar 18.2010 — Thanks. Kindly check back here for replies from others, I guessed that is what you want, I might be wrong and someone else might have better advice.
×

Success!

Help @JoseSilva spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...