php parts explode _SERVER SERVER_NAME len sizeof parts _DOMAIN sprintf

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
$parts = explode('.', $_SERVER['SERVER_NAME']);
$len = sizeof($parts);
$_DOMAIN = sprintf('%s.%s', $parts[$len - 2], $parts[$len - 1]);
$_MAP = array(
'fiesta.zz' => 0,
'fiesta_1.zz' => 1,
'fiesta_2.zz' => 2,
'fiesta_3.zz' => 3,
'fiesta_4.zz' => 4,
);
$_DEFAULT_SID = 1;
if (isset($_MAP[$_DOMAIN])) {
$_SID = $_MAP[$_DOMAIN];
} else {
$_SID = $_DEFAULT_SID;
}
//printf('domain: %s, sid: %d', $_DOMAIN, $_SID);
//die();
if (!$_SID) {
$_DBNAME = 'fiesta';
} else {
$_DBNAME = sprintf('fiesta_%d', $_SID);
}
?>