开发者

API key for multiple domain script, google map V2

could any one check why my script below is not working please?

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

Thanks a lot!!


You can avoid this whole problem: Maps API keys now support multiple domains (and you can edit authorised domains at any time). See Obtaining an API key for more details.


I totally agree with Wrikken, it does not seem that you echoed the variable during the process. Maybe this approach would help:

            <?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>";  

            ?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜