Jump to content

Question about defining a variable


ellis

Recommended Posts

Hi guys very new to php so hopefully this is not a painfully obvious thing.

 

Currently what I have for a site I made is a config file where I define a destination link. Such as so

define("DESTINATION", "http://site.com");

What I am trying to do now is make the link that DESTINATION gets be based on GeoIP. So it would need a bunch of if elseif's.

 

Basically there are a few countries that get the main DESTINATION link. Then the rest of the countries not in this I guess you could call it "white label" would mostly get differing individual links. So if US, CA, UK, AU are all in whitelabel they get stuck with the same link, any other geo country designation starts going through the list of countries for its proper destination. Can anyone be nice enough to point me into the right direction in how I should go about making this happen.

 

Thank you for the help and time!

 

 

Link to comment
Share on other sites

Sorry for the mix up on terms. Thanks for the corrections on those, @Hall of Famer, you were spot on as to what I meant initially.

 

Well here is what I came up with but I do not think I am doing this correctly still.

define("DESTINATION", '');
if($geoip_country_code == 'UK')
{
        $destination="http://www.uk.co.uk";
}
elseif($geoip_country_code == 'CA')
{
        $destination="http://www.ca.ca";
}
elseif($geoip_country_code == 'FR')
{
        $destination="http://www.fr.com";
}
else
{
        $destination="http://www.therest.com";
}
Edited by ellis
Link to comment
Share on other sites

To define the variable destination as '' you would do:

$destination = '';

 

I don't understand what you're doing on the fist line. The rest of your code looks fine to me. Could make it a little easyer to read with a switch/case statement but it would be functionally the same as your if elseif's.

 

To call the url from your variable:

echo $destination;

That will just print the string stored. Pass it to your script in your own way.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.