google maps api keys to be set webserver-wide, (as env var? inside apache?)
Posted
by ~knb
on Stack Overflow
See other posts from Stack Overflow
or by ~knb
Published on 2010-05-26T12:00:54Z
Indexed on
2010/05/26
12:41 UTC
Read the original article
Hit count: 227
I have a web site with many virtual hosts and each registered with several domain names (ending in .org, .de), site1.mysite.de, site2.mysite.org
Then I have different templating systems based on several programming languages (perl and php) in use on the web server.
The Google Maps Api requires a unique Google Maps api key for each vhost.
I want to have something like a web-server wide variable $goomapkey that I can call from inside my code.
In PHP code, Now I have a kludgy case-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, ...
}
... inside my php-based CMS. A non-ideal solution, because it is, php-only, and I still have to set it at several html templates inside the CMS, and there are too many cases.
I want the google maps api key to be set by the apache web server who examines the request *early in the request loop before any php page template code is constructed and evaluated.
is an environment variable a good solution?
which technology should be used to set the $goomapkey variable?
I'd prefer mod_perl2 Apache request handler, but the documentation is confusing (many API changes in the past ). Which Apache module could I use?
- Is there a built-in Apache module that does the same thing?
© Stack Overflow or respective owner