Reputation: 1322
I am creating a site for 2 companies to share. In development, the URL structures for both sites are: 1) xx.domain.dev 2) yy.domain.dev
Live, they will be: 1) site.xx.com 2) site.yy.com
Once a user logs into the site, sessions are set for either site depending on the user's company email address.
I would like to set those sessions earlier, though. Ideally as soon as the site is hit, depending on which domain or subdomain they are coming from, I'd set a session accordingly.
Basically, is there a way to detect the URL the site is being loaded from and set a session property accordingly?
Upvotes: 0
Views: 77
Reputation: 71
I did similar stuff and shared a codeigniter application across many sites.
I am doing something like this inside application/config/config.php :
$domain= $_SERVER['SERVER_NAME'];
switch($domain){
case 'www.domain1.com' :
case 'm.domain2.com' :
$config['domain_name'] = 'Some domain';
$config['country']= 'Some country';
break;
case 'anotherdomain.fr' :
// ...
}
So I guess same thing can work for you, just ureplace with your values, and set the $_SESSION within the cases. Something like :
// initialize session if not already done
$domain= $_SERVER['SERVER_NAME'];
switch($domain){
case 'xx.domain.dev' :
$_SESSION['site']= 'xx';
break;
case 'yy.domain.dev' :
$_SESSION['site']= 'yy';
break;
}
Upvotes: 1