Forum Moderators: coopster
I have the following question.
When using services as api map from google im in a weird position cause i own more extensions of my domain.
google gives a key for the maps..
Situation:
Lets say my domain is justfake.com
But i als own justfake.de , justfake.co.uk etc..
Okay in my situation just 2.
But some people prefer to loggin on the other extension and if thats the one not registered they get an annoying message from google that the key was ment for other down.
So i was thinking....if i register another key ,can i use simple scripting so it automatically switches between the 2 extensions?
Like if you login from co.uk get $apikey 1
if from .com get $apikey 2
Possible?
Lol...you didnt understand?
Okay...again....i need a sample (written in php) how i can do the following :
that i can use 2 google maps keys on 1 address.
i tried ..
$referer = $_SERVER['HTTP_REFERER'];
if ( strstr($referer, "http://www.mysite.com"))
{
$apikey = my key 1;
}
else
{
$apikey = my key 2;
}
but that doesnt work..
rephrase my question?Lol...you didnt understand?
My apologies... Obviously these were the bits I didn't understand:
So i was thinking....if i register another key ,can i use simple scripting so it automatically switches between the 2 extensions?(...)
Possible?
If you'd posted your script extract in the first place, it would have been much more helpful.
(A useful link for future reference:
[catb.org...]
I'd suggest trying HTTP_HOST instead of HTTP_REFERER, as the former will always be set. The rest is a simple matter of making sure you're comparing the right strings.
$_SERVER['HTTP_HOST']and/or
$_SERVER['HTTP_REFERER']variables and exiting your script to see what is in them? Then work your way into the code to see what value is being evaluated in the control structure (your if statement) to see what is happening next and why.
<edit>fixed formatting</edit>
[edited by: coopster at 6:39 pm (utc) on July 4, 2006]
echo 'http_host: '.$_SERVER['HTTP_HOST'];
echo '<br />http_referer: '.$_SERVER['HTTP_REFERER'];
exit;
Good luck!
Try dumping out the $_SERVER variables so you can see if they hold what you expect:
<?php
if (strpos [php.net]($_SERVER [php.net]['HTTP_HOST'], "http://www.example.com") === FALSE) {
$something = 1;
} else {
$something = 2;
}
print $something;
print '<pre>';
print_r($_SERVER);
exit('</pre>');
?>
if (strstr($_SERVER['HTTP_REFERER'],"mysite.com")) {
$apikey = "key1";
} else {
$apikey = key2;
}
this works but as long people go to the page from the menu,whitch means root for the referer.
so if someone goes to the page from another link,or refreshes....whatever....it doesnt work cause it grabs that referer and that fails...
anyway to prevent that?
If you are truly trying to figure out which subdomain people are on then your best bet is to grab it during the login process. Grab whichever page they are requesting and store it in a session variable. Then push them over to your login script. During the login process you can analyze the requested URI and handle accordingly.