【问题标题】:API key for multiple domain script, google map V2多域脚本的 API 密钥,谷歌地图 V2
【发布时间】:2010-09-30 22:36:51
【问题描述】:

谁能检查我下面的脚本为什么不起作用?

<script src="http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=
<?php  
$this->googleMapsApiKey = $this->getValueFromDB("google", "googleMapsApiKey");
            if ($_SERVER['HTTP_HOST']=='www.ABC.info') { 
        $this->googleMapsApiKey = "Googlemap-keys";
            } elseif ($_SERVER['HTTP_HOST']=='www.CBA.com') { 
        $this->googleMapsApiKey = "Googlemap-keys";
        } 
?>" type="text/javascript"></script>

非常感谢!!

【问题讨论】:

  • echo $this-&gt;googleMapsApiKey; 在 PHP 脚本的末尾可能吗? HTML 中的键现在为空。

标签: php google-maps-api-2


【解决方案1】:

您可以避免整个问题:Maps API 密钥现在支持多个域(并且您可以随时编辑授权域)。详情请见Obtaining an API key

【讨论】:

    【解决方案2】:

    我完全同意 Wrikken 的观点,您似乎没有在此过程中回显变量。也许这种方法会有所帮助:

                <?php  
                print '<script src="http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=';
                $this->googleMapsApiKey = $this->getValueFromDB("google", "googleMapsApiKey");
                          switch ($_SERVER['HTTP_HOST'])
                          {
                         //Specific for a domain, but I think that the default handles it against your DB automatically
                         //case 'www.ABC.info' : $this->googleMapsApiKey = "Googlemap-keys";
                         // break;
    
                         //Same here
                         // case 'www.CBA.com': $this->googleMapsApiKey = "Googlemap-keys";
                         // break;
    
                          default: $this->googleMapsApiKey = "Googlemap-keys";
                          }
    
                echo "$this->googleMapsApiKey type=\"text/javascript\"></script>";  
    
                ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-06
      • 1970-01-01
      • 2016-09-30
      相关资源
      最近更新 更多