Forum Moderators: coopster

Message Too Old, No Replies

using 2 googlemap key's to switch on 2 site extensions

2 googlemap key's

         

john1000

3:48 pm on Jul 2, 2006 (gmt 0)

10+ Year Member



Hello,

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?

zCat

8:18 pm on Jul 2, 2006 (gmt 0)

10+ Year Member



Yes.

john1000

8:36 pm on Jul 2, 2006 (gmt 0)

10+ Year Member



i hoped for a solution....
not just ...yes

zCat

9:07 pm on Jul 2, 2006 (gmt 0)

10+ Year Member



In that case... you'd have to rephrase your question.

john1000

9:20 pm on Jul 2, 2006 (gmt 0)

10+ Year Member



rephrase my question?

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

zCat

9:33 pm on Jul 2, 2006 (gmt 0)

10+ Year Member



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.

john1000

10:08 pm on Jul 2, 2006 (gmt 0)

10+ Year Member



well i tried a few combinations but non of it works...

maccas

10:25 pm on Jul 2, 2006 (gmt 0)

10+ Year Member



What about

if ( strpos($referer, "http://www.mysite.com"))

maccas

10:34 pm on Jul 2, 2006 (gmt 0)

10+ Year Member



Actually I do something similar but I do it like this.

if( strpos($_SERVER['HTTP_REFERER'],"http://yoursite") === FALSE)
{
$something = ;
}
else
{
$something = ;
}

Whether this is the best way or not...

john1000

10:35 pm on Jul 2, 2006 (gmt 0)

10+ Year Member



also nothing.... :(

john1000

10:48 pm on Jul 2, 2006 (gmt 0)

10+ Year Member



ok maccas..ill try that...we crossed posts..

john1000

10:52 pm on Jul 2, 2006 (gmt 0)

10+ Year Member



unfortunately maccas....with your sample non of the extensions work anymore..

maccas

9:42 am on Jul 3, 2006 (gmt 0)

10+ Year Member



I am not sure why, I just tried a simple script on 3 different servers and it worked on all.

What does this script print when you go to it?

<?php
if( strpos($_SERVER['HTTP_HOST'],"http://www.yoursite.com") === FALSE)
{
$something = 1;
}
else
{
$something = 2;
}
print $something;
?>

john1000

11:18 am on Jul 3, 2006 (gmt 0)

10+ Year Member



no matter what extension i use,it constantly shows 1

john1000

7:20 pm on Jul 3, 2006 (gmt 0)

10+ Year Member



anyone?

coopster

4:08 pm on Jul 4, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



How about dumping the value of the
$_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]

john1000

6:36 pm on Jul 4, 2006 (gmt 0)

10+ Year Member



thanks coopster,but building that is beyond my knowledge.... so a sample/howto would be appreciated..

eelixduppy

6:45 pm on Jul 4, 2006 (gmt 0)



Basically coopster is saying to check the values of the variables:

echo 'http_host: '.$_SERVER['HTTP_HOST'];
echo '<br />http_referer: '.$_SERVER['HTTP_REFERER'];
exit;

Good luck!

coopster

6:46 pm on Jul 4, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Well you said you tried one of the solutions but you didn't check to see what or why it failed, you merely stated that it failed. You need to learn how to troubleshoot [webmasterworld.com]. We can only help those who are willing to help themselves ;)

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>');
?>

Have a look at your site's $_SERVER array to see what the HTTP_HOST and/or HTTP_REFERER index values are and if they are indeed what you expect to see.

john1000

7:13 pm on Jul 4, 2006 (gmt 0)

10+ Year Member



ok done that ands get nice printed overview...but forgive my stupidity but what should i be looking for..?
The both mentioned HOST and REFERER show bothe the same site.extension

john1000

8:42 pm on Jul 4, 2006 (gmt 0)

10+ Year Member



ok i got it running now using it like this :

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?

coopster

3:10 pm on Jul 6, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Well, HTTP_REFERER is not a good variable to rely on. It can be spoofed, it can be told not to be sent at all, ... it is just not very reliable.

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.