Multiple domains, multiple databases with only one script

Hello all,

i need create multiple (sub)domains on one server (linux) but.. i want all domains read same script location (for example /var/script/index.php...)

lets say :
one.domain.com
sec.domain.com
thre.domain.com

db_one
db_sec
db_thre

when u come to www.domain.com u get login page where u can chose (sub) domains, and when u chose sub domain, enter user and password then click on login button u will be redirected to selected domain, you will be using db_one config and u will be logged in (if all info are good - user, pass).

so my final question is :
is this posible to have one script and using this one script in multiple domains/subdomains and how ?

ty.

PS. sorry for my bad english :S
Marshall2056Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Sebastian TalmonConnect With a Mentor System Engineer Datacenter SolutionsCommented:

ok...

i think the only thing that will work is:
(given all domains are subdomains of one main domain, otherwise cookies could not be shared)

* login-form on www.domain.ext,   target of form also www.domain.ext
* www.domain.ext  only opens a session, with session_save_path in a shared directory between the domains, and with cookie-path  .domain.ext  (take care of the dot before the domain!)
* after setting the cookie/open a session, write username/password as session-variables, and redirect to the subdomain
* on first page of subdomain, use the same session, and check the user/password-session-variables against the corresponding database
* grant rights to the user if user/pass is correct

0
 
Sebastian TalmonSystem Engineer Datacenter SolutionsCommented:

based on your path (var/script) is it correct that you have your own webserver, and do not need a solution for shared hosting?

In the apache-config, you could allow the use of symlinks in linux  (set SymLinksIfOwnerMatch to on). Based on this, you could create symlinks in all three homedirs to this central file. PHP takes this file just as if it was duplicated for all three domains, with  require_once('db.inc.php') or something similar you could include code that is different for the three domains (i.e. the database parameters)
0
 
Monis MontherSystem ArchitectCommented:
Configure Virtual Hosts under your apache

Leave the main virtual host with your index.php scripts

Configure Redirects for the others


Each one of those is a topic that you need to search for on google, I advice starting with the Apache official documentation

This is for version 2.2

http://httpd.apache.org/docs/2.2/



0
 
Sebastian TalmonSystem Engineer Datacenter SolutionsCommented:

does the user has to choose which subdomain he wants to connect to BEFORE the login, or is there a need for an option-field in the login-form itself?

If you have to choose in the login-form, then you will have to do the login on the main domain (www) and do a redirect after login - but then it gets a little bit complex as you have to transfer the session between two domains/vhosts (from the main site which checks the login, to the target domain where the content is)

If you could live with having only links to the three subdomain on the main site, and do the login on each subdomain, it is much easier as the login-session remains in only one domain  (sharing the php-code for login-script between the three subdomains could be made with symlinks as mentioned before)

0
 
Marshall2056Author Commented:
well i want something similar to egroupware
before u login u choose for domain or u can type like username@domain.ext
then script will redirect to domain.ext and check db for username and password on this domain
but egroupware using one database ..i will use one database for one domain

aka domain name = one.domain.ext  db name = one.domain.ext

0
All Courses

From novice to tech pro — start learning today.