ellis Posted April 24, 2013 Share Posted April 24, 2013 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! Quote Link to comment Share on other sites More sharing options...
Hall of Famer Posted April 25, 2013 Share Posted April 25, 2013 Are you sure you are even defining a variable at all? the keyword define is used to declare PHP constants, these aint variables since their contents cannot be modified after you create the constants. Quote Link to comment Share on other sites More sharing options...
jugesh Posted April 25, 2013 Share Posted April 25, 2013 You can declare variables like: $SiteUrl="http://site.com"; Quote Link to comment Share on other sites More sharing options...
sjvmv Posted April 25, 2013 Share Posted April 25, 2013 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 http://www.rightern.com Quote Link to comment Share on other sites More sharing options...
ellis Posted April 25, 2013 Author Share Posted April 25, 2013 @sjvmv Thanks for that I am going to work with your example, I think it shows me enough for what I want to do. Will post back what I come up with for criticism. Quote Link to comment Share on other sites More sharing options...
ellis Posted April 28, 2013 Author Share Posted April 28, 2013 (edited) 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 April 28, 2013 by ellis Quote Link to comment Share on other sites More sharing options...
Phear46 Posted April 28, 2013 Share Posted April 28, 2013 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.