DomenicF Posted September 14, 2012 Share Posted September 14, 2012 Hey guys, My host doesn't support the native GeoIP functions of PHP, so they suggest to use the Perl module that they have installed on the OS to do the work. Here is my code: $country = shell_exec('geoip-lookup '.$_SERVER['REMOTE_ADDR']); if($country == "US") { $temp = $temp_F; echo "Fahrenheit"; } elseif($country != "US") { $temp = $temp_C; echo "Celcius"; } else { echo "This is a recording."; } Now, even when $country is definitely set to US, it still always comes back to Celcius. I've already tried doing the script without the elseif, and it doesn't make a difference. Looking for some help. Quote Link to comment https://forums.phpfreaks.com/topic/268379-geoip-help-kinda/ Share on other sites More sharing options...
ManiacDan Posted September 14, 2012 Share Posted September 14, 2012 You've echoed $country inside these IF blocks and it echoes "USCelcius"? Quote Link to comment https://forums.phpfreaks.com/topic/268379-geoip-help-kinda/#findComment-1377938 Share on other sites More sharing options...
scootstah Posted September 14, 2012 Share Posted September 14, 2012 Can we see the code for the geoip-lookup program? Quote Link to comment https://forums.phpfreaks.com/topic/268379-geoip-help-kinda/#findComment-1377967 Share on other sites More sharing options...
DomenicF Posted September 14, 2012 Author Share Posted September 14, 2012 You've echoed $country inside these IF blocks and it echoes "USCelcius"? Yes, it echoes Celcius and when I echo $country it echoes US. Can we see the code for the geoip-lookup program? I don't have it, but I believe it is a perl module. Here's my host's wiki: http://wiki.dreamhost.com/GeoIP Here is an example output of geoip-lookup: $ geoip-lookup google.com US Quote Link to comment https://forums.phpfreaks.com/topic/268379-geoip-help-kinda/#findComment-1377971 Share on other sites More sharing options...
beyzad Posted September 14, 2012 Share Posted September 14, 2012 Hi. Did you tried var_dump() ? Quote Link to comment https://forums.phpfreaks.com/topic/268379-geoip-help-kinda/#findComment-1377978 Share on other sites More sharing options...
DomenicF Posted September 14, 2012 Author Share Posted September 14, 2012 Hi. Did you tried var_dump() ? I just tried it, and you may be on to something. The output of var_dump is: string(3) "US " So, I changed my code to: $country = shell_exec('geoip-lookup '.$_SERVER['REMOTE_ADDR']); if($country == "US ") { $temp = $temp_F; echo "Fahrenheit<br />"; echo $country."<br />"; var_dump($country); } elseif($country != "US ") { $temp = $temp_C; echo "Celcius<br />"; echo $country."<br />"; var_dump($country); } else { echo "This is a recording.<br />"; var_dump($country); } And I still have the same results. With that being said, I did: trim($country); And it still outputs as 3 characters. So, I'm not sure what's going on. Quote Link to comment https://forums.phpfreaks.com/topic/268379-geoip-help-kinda/#findComment-1377982 Share on other sites More sharing options...
DomenicF Posted September 14, 2012 Author Share Posted September 14, 2012 So in the end I just assigned trim() to another variable and got it to work. My code now is as follows: $country = shell_exec('geoip-lookup '.$_SERVER['REMOTE_ADDR']); $output_country = trim($country); if($output_country == "US") { $temp = $temp_F; echo "Fahrenheit<br />"; echo $country."<br />"; var_dump($country); } elseif($output_country != "US") { $temp = $temp_C; echo "Celcius<br />"; echo $country."<br />"; var_dump($country); } else { echo "This is a recording.<br />"; var_dump($country); } Appreciate your time! Quote Link to comment https://forums.phpfreaks.com/topic/268379-geoip-help-kinda/#findComment-1377987 Share on other sites More sharing options...
scootstah Posted September 14, 2012 Share Posted September 14, 2012 For what it's worth, you can just do this: $country = trim(shell_exec('geoip-lookup '.$_SERVER['REMOTE_ADDR'])); Quote Link to comment https://forums.phpfreaks.com/topic/268379-geoip-help-kinda/#findComment-1378006 Share on other sites More sharing options...
DomenicF Posted September 14, 2012 Author Share Posted September 14, 2012 Thanks, that seems a lot cleaner. Quote Link to comment https://forums.phpfreaks.com/topic/268379-geoip-help-kinda/#findComment-1378008 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.