Re: Déploiement de PHPBB sous debian

Pàgina inicial

Reply to this message
Autor: Edgar Bonet
Data:  
A: Liste Guilde
Assumpte: Re: Déploiement de PHPBB sous debian
Salut !

Frédéric a écrit :
> [...]
>
> <?php
> if ($_SERVER["HTTP_HOST"] == "forum.example.com")
> {
>    $dbms = 'mysql';

>
>    $dbhost = 'mysql.example.com';
>    $dbname = 'phpbb_sites';
>    $dbuser = 'mylogin';
>    $dbpasswd = 'mypassword';

>
>    $table_prefix = 'phpbb2_';

>
> }
> else if ($_SERVER["HTTP_HOST"] == "forum.example.net")
> {
>    $dbms = 'postgres';

>
>    $dbhost = 'postgres.example.net';
>    $dbname = 'phpbb_sites';
>    $dbuser = 'mylogin';
>    $dbpasswd = 'mypassword';

>
>    $table_prefix = 'phpbb2_';

>
> }
> else if ...
>
> C'est franchement dégueu, comme façon de procéder !


Si tu aimes mieux, voici une légère variante :

$virtual_hosts = array(
     'forum.example.com' => array(
         'dbms' => 'mysql',
         'dbhost' => 'mysql.example.com',
         'dbname' => 'phpbb_sites',
         'dbuser' => 'mylogin',
         'dbpasswd' => 'mypassword',
         'table_prefix' => 'phpbb2_'
     ),
     'forum.example.net' => array(
         'dbms' => 'postgres',
         'dbhost' => 'postgres.example.net',
         'dbname' => 'phpbb_sites',
         'dbuser' => 'mylogin',
         'dbpasswd' => 'mypassword',
         'table_prefix' => 'phpbb2_'
     )
     // ... etc ...
);


if (array_key_exists($_SERVER['HTTP_HOST'], $virtual_hosts)) {
     $this_vhost = $virtual_hosts[$_SERVER['HTTP_HOST']];
     $dbms = $this_vhost['dbms'];
     $dbhost = $this_vhost['dbhost'];
     $dbname = $this_vhost['dbname'];
     $dbuser = $this_vhost['dbuser'];
     $dbpasswd = $this_vhost['dbpasswd'];
     $table_prefix = $this_vhost['table_prefix'];
}
else die('unknown virtual host');


Edgar.