greatbigterry Posted November 15, 2014 Share Posted November 15, 2014 PHP newb here - apologies if the answer to this is really simple. I've tried to add a geotargetting code into my website but it appears the elseif part isn't working, no matter what I do. Here's the code - any idea why if is fine, and else is fine, but elseif isn't? <?php if (function_exists('showCountryContentInPage')) { if(showCountryContentInPage(array("us", "ca"),1)) { // US $region = 'USA'; $country = codediesel_get_users_country(); $store_url = 'URL here'; } elseif(showCountryContentInPage(array("at", "es", "cy", "fi", "ee", "fr", "de", "el", "ie", "it", "mt", "lu", "lv", "nl", "pt", "sk", "si", "be"),1)) { // Europe $region = 'Europe'; $country = codediesel_get_users_country(); $store_url = 'URL here'; } else { // UK $region = 'UK'; $country = codediesel_get_users_country(); $store_url = 'URL here'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/292476-elseif-not-working-any-idea-why/ Share on other sites More sharing options...
Barand Posted November 15, 2014 Share Posted November 15, 2014 I suggest you check your function showCountryContentInPage() Quote Link to comment https://forums.phpfreaks.com/topic/292476-elseif-not-working-any-idea-why/#findComment-1496645 Share on other sites More sharing options...
greatbigterry Posted November 16, 2014 Author Share Posted November 16, 2014 (edited) Thanks Barand - so the code above looks fine? If the function showCountryContentInPage was broken wouldn't that mean the US version would stop working too? Edited November 16, 2014 by greatbigterry Quote Link to comment https://forums.phpfreaks.com/topic/292476-elseif-not-working-any-idea-why/#findComment-1496722 Share on other sites More sharing options...
Barand Posted November 16, 2014 Share Posted November 16, 2014 (edited) Depends on how it is "broken". Could be that it defaults to US, or maybe it always returns "true" Edited November 16, 2014 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/292476-elseif-not-working-any-idea-why/#findComment-1496724 Share on other sites More sharing options...
ginerjm Posted November 16, 2014 Share Posted November 16, 2014 1 - I never understand why people use function_exists. If you are writing the code, didn't you write that function? So why test for it? 2 - What makes you suspect a problem here? Tell us what happens - or better yet debug your function to see what it is doing (add some echos). Quote Link to comment https://forums.phpfreaks.com/topic/292476-elseif-not-working-any-idea-why/#findComment-1496725 Share on other sites More sharing options...
ginerjm Posted November 16, 2014 Share Posted November 16, 2014 AND - why do you have this structure in your main code rather than placed inside the function? Wouldn't that make more sense? Quote Link to comment https://forums.phpfreaks.com/topic/292476-elseif-not-working-any-idea-why/#findComment-1496726 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.