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
https://forums.phpfreaks.com/topic/277277-question-about-defining-a-variable/
Share on other sites

Hi Ellis,

 

Try this i hope this will help you.

 

First define the variable as empty

 

 

$description = '';

 

if($data == 'uk')

{

    $description = "http://www.rightern.com/";

}else{

    $description = "http://www.rightern.com/";

}
 
 
Thanks,
Vijay

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

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.

Archived

This topic is now archived and is closed to further replies.

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