I've got a site with lots of virtual hosts and every registered with several domains (ending insnet, .p), site1.mysite.p, site2.mysite.org

I Quickly have different templating systems according to several programming languages (perl and php) being used on the internet server.

The Google Maps Api takes a unique Google Maps api key for every vhost.

I wish to have something similar to an internet-server wide variable $goomapkey will be able to call from the inside my code.

In PHP code, Now I've got a kludgy situation-analysis solution like

 $domain = substr($_SERVER['SERVER_NAME'], -3);
 if (".de" == $domain){
   //if ("xxxxxx" eq substr($ENV{SERVER_NAME}, 0, 5)){

   //  $gookey = "ABQIAAA...";
   //} else {
     //site1.de   
     $gookey = "ABQIAAAA1Js...";
   //}
 } elseif ("dev" == substr($_SERVER['SERVER_NAME'], 0, 3)){
   //dev.mysite.org
   $gookey = "ABQIAAAA1JsSb...";
 } else {
   //www.mysite.org
   $gookey = "ABQIAAAA1JsS...";
   //TODO: Add more keys for each virtual host, for my.machinename.de, IP-address based URL, ...
 }

... within my php-based Content management systems. A non-ideal solution, since it is, php-only, and that i still need to place it at a number of html templates within the Content management systems, and you will find a lot of cases.

I would like the google maps api answer to be set through the apache web server who examines the request *at the start of the request loop before any php page template code is built and examined.

  • is definitely an atmosphere variable a great choice?

  • which technology should be employed to set the $goomapkey variable?

I'd prefer mod_perl2 Apache request handler, however the documentation is confusing (many API changes previously ). Which Apache module could I personally use?

  • It is possible to built-in Apache module that does exactly the same factor?

Surely this can be a little overkill for just a couple of domain names? I am talking about, you've clearly needed to feel the procedure for using for any key for every domain, why don't you only use each type in each project individually?

Probably the most elegant solution is always to result in the change to Google Maps API v3, which no more requires an API key.

Is definitely an atmosphere variable a great choice?

I'd hesitate to make use of atmosphere variables to keep a "key", except API secrets aren't secret (anybody can easily see it with "view source"), therefore it appears vaguely sensible.

Whether you believe it is a "good" idea differs matter — it is a adding breach, but so's anything else. In case your web framework (or whatever you are using) has some kind of site config, this is the apparent spot to place it. You could have the config code load it in the atmosphere variable, but when you retain it within the config then it is much simpler to alter later

I'd prefer something similar to

$apikeys = array(
  "site1.de" => "...",
  "dev.mysite.org" => "...", 
  "www.mysite.org" => "...",
  "" => "...", // default
);

Then your code loops within the array, finds a long suffix match, and uses the related key. It's the benefit it's simpler to port between different languages (you may also write genapikeys.pl which creates gmapapikeys.php). I additionally don't believe there's any point getting a default key — IIRC Google Maps rejects your request when the key does not match the "Referer".

A far more general solution is always to turn back hostnames (i.e. p.site1, org.mysite.www) after that you can have "com.hostingcompany.www/mysite/".

Obviously, IP addresses have been in reverse order, and IPv6 is really a load of fun. I am unsure if API secrets support either, though, so it may be irrelevant.

By trying to populate the variable via mod_perl2, it will not be accessible to PHP - similarly, your PHP include files aren't open to PERL.

An atmosphere variable appears like a great compromise - unless of course you're already loading comon data from documents / a database.

It is possible to built-in Apache module that does exactly the same factor?

Yes - mod_env and also the SetEnv directive

C.