谷歌地图和钥匙在线更改
我正在寻找 php 专家来帮助我解决这个奇怪的问题。 下面添加的这个脚本有时效果很好。 我有三个域指向一个目录。 Google 地图需要每个域都有唯一的 api 密钥。 我的脚本必须在线更改键值。 我看到 IE8 中的页面总是正确显示,但从 Chrom 和 Firefox 中,此脚本有问题,但并非总是如此。当然,我控制了页面的源,并且应该是脚本 src 的地方是空的。 谢谢 祝你今天过得愉快!
页面的 HEAD 中添加了完整的代码。
<?php
if ($_SERVER['HTTP_HOST']=='napuzaka.pl')
{echo "<script src='http://maps.google.com/maps?file=api&v=2&key=http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAYTZHyOQ5V62SeMKaQnfsmBTpouANZ5f-taQv7LHvODzA4dkDHBSIDoDMuDCbfgg0tAyoHhFajBNCJQ' type='text/javascript'></script>"; }
if ($_SERVER['HTTP_HOST']=='xn--napuaka-zwb.pl')
{echo "<script src='http://maps.google.com/maps?file=api&v=2&key=http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAYTZHyOQ5V62SeMKaQnfsmBSz8IVGRhEo79udyNR7B2dzTza61xRpT9lPIg18vhQmddrMIlSVereK3g' type='text/javascript'></script>";}
if ($_SERVER['HTTP_HOST']=='xn--przychodnia-na-puaka-yle.pl')
{echo "<script src='http://maps.google.com/maps?file=api&v=2&key=http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAYTZHyOQ5V62SeMKaQnfsmBTIBRlPbe0ldXIT_VQB31noUDT8mRReXxc12wAWIs4fuEXiTbsZ0HvViA' type='text/javascript'></script>";}
?>
I looking for expert of php who wants to help me in this strange problem.
This script added bellow sometimes works good.
I have three domains pointed to one directory. Google maps requires api key unique for each domain.
My script have to change the key value online.
I see that page from IE8 always are showed correctly but from Chrom and Firefox this script has problem but not always. Ofcourse I controled source of page and there was empty where should be script src.
Thank you
Have a nice day!
There is full code added in HEAD of page.
<?php
if ($_SERVER['HTTP_HOST']=='napuzaka.pl')
{echo "<script src='http://maps.google.com/maps?file=api&v=2&key=http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAYTZHyOQ5V62SeMKaQnfsmBTpouANZ5f-taQv7LHvODzA4dkDHBSIDoDMuDCbfgg0tAyoHhFajBNCJQ' type='text/javascript'></script>"; }
if ($_SERVER['HTTP_HOST']=='xn--napuaka-zwb.pl')
{echo "<script src='http://maps.google.com/maps?file=api&v=2&key=http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAYTZHyOQ5V62SeMKaQnfsmBSz8IVGRhEo79udyNR7B2dzTza61xRpT9lPIg18vhQmddrMIlSVereK3g' type='text/javascript'></script>";}
if ($_SERVER['HTTP_HOST']=='xn--przychodnia-na-puaka-yle.pl')
{echo "<script src='http://maps.google.com/maps?file=api&v=2&key=http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAYTZHyOQ5V62SeMKaQnfsmBTIBRlPbe0ldXIT_VQB31noUDT8mRReXxc12wAWIs4fuEXiTbsZ0HvViA' type='text/javascript'></script>";}
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果不起作用,只需打印 $_SERVER['HTTP_HOST'] 并将其添加到 if... 与浏览器如何解析 IDN(国际化域名)有关 http://en.wikipedia.org/wiki/Internationalized_domain_name
Just print $_SERVER['HTTP_HOST'] in the situations that it doesn't work and add them to the if... It is related on how browsers parse IDN (Internationalized domain name) http://en.wikipedia.org/wiki/Internationalized_domain_name
为什么不使用变量来控制域,然后使用 switch 语句
回显
该行?此外,使用
print
代替echo
可以在处理过程中节省一些内存,因为echo
函数有自己的微工厂,只能使用如果您为了加快速度而打印变量或包含变量的文本。Why not instead use a variable to control the domain and then
echo
that line with a switch statement?Also, using
print
instead ofecho
saves some memory during the process, as theecho
function has its own micro-factory and should be used only if you are printing variables or text with variables in it for sake of making it faster.