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