dsb0003795 2010-05-26 12:00
浏览 62
已采纳

谷歌地图api键设置为webserver范围,(作为env var?在apache内?)

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?
  • 写回答

3条回答 默认 最新

  • douji9816 2010-05-26 12:40
    关注

    Surely this is a little overkill for only a few domains? I mean, you've obviously had to go through the process of applying for a key for each domain, why not just use each key in each project independently?

    The most elegant solution would be to make the switch to Google Maps API v3, which no longer requires an API key.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 请问为什么我配置IPsec后PC1 ping不通 PC2,抓包出来数据包也并没有被加密
  • ¥200 求博主教我搞定neo4j简易问答系统,有偿
  • ¥15 nginx的使用与作用
  • ¥100 关于#VijeoCitect#的问题,如何解决?(标签-ar|关键词-数据类型)
  • ¥15 一个矿井排水监控系统的plc梯形图,求各程序段都是什么意思
  • ¥15 ensp路由器启动不了一直报#
  • ¥50 安卓10如何在没有root权限的情况下设置开机自动启动指定app?
  • ¥15 ats2837 spi2从机的代码
  • ¥200 wsl2 vllm qwen1.5部署问题
  • ¥100 有偿求数字经济对经贸的影响机制的一个数学模型,弄不出来已经快要碎掉了