谷歌地图和钥匙在线更改

发布于 2024-10-21 20:34:59 字数 1229 浏览 2 评论 0原文

我正在寻找 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦太阳 2024-10-28 20:34:59

如果不起作用,只需打印 $_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

烟雨扶苏 2024-10-28 20:34:59

为什么不使用变量来控制域,然后使用 switch 语句回显该行?

$page = $_SERVER['PHP_SELF'];

switch ($page)
{

case 'http://xn--przychodnia-na-puaka-yle.pl': 
print '<script src="http://maps.google.com/maps?file=api&v=2&hl=en&sensor=false&key="ABQIAAAAYTZHyOQ5V62SeMKaQnfsmBTIBRlPbe0ldXIT_VQB31noUDT8mRReXxc12wAWIs4fuEXiTbsZ0HvViA" type="text/javascript"></script>';

break;

case 'http://napuzaka.pl': /* same with this case just different API Key*/ 
break;

case 'http://xn--napuaka-zwb.pl': /* same with this case just different API Key*/ 
break;

}

此外,使用 print 代替 echo 可以在处理过程中节省一些内存,因为 echo 函数有自己的微工厂,只能使用如果您为了加快速度而打印变量或包含变量的文本。

Why not instead use a variable to control the domain and then echo that line with a switch statement?

$page = $_SERVER['PHP_SELF'];

switch ($page)
{

case 'http://xn--przychodnia-na-puaka-yle.pl': 
print '<script src="http://maps.google.com/maps?file=api&v=2&hl=en&sensor=false&key="ABQIAAAAYTZHyOQ5V62SeMKaQnfsmBTIBRlPbe0ldXIT_VQB31noUDT8mRReXxc12wAWIs4fuEXiTbsZ0HvViA" type="text/javascript"></script>';

break;

case 'http://napuzaka.pl': /* same with this case just different API Key*/ 
break;

case 'http://xn--napuaka-zwb.pl': /* same with this case just different API Key*/ 
break;

}

Also, using print instead of echo saves some memory during the process, as the echo 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文