0

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

<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>

非常感谢!!

4

2 回答 2

2

您可以避免整个问题:Maps API 密钥现在支持多个域(并且您可以随时编辑授权域)。有关更多详细信息,请参阅获取 API 密钥

于 2012-02-09T23:51:15.053 回答
0

我完全同意 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>";  

            ?>
于 2011-04-29T10:31:57.000 回答