Anyone that can do this will get $7USD via paypal. Write a short function (<10 lines) to obtain the user's country code using the geoplugin.net service. No warnings or errors are to be generated if geoplugin.net does not respond. A maximum of 15 seconds is allowed, else return blank code. The parent script timeout must not be affected. Please post the answer in the same thread. The best answer will be reward the money + job offer. Kind Regards, Ormus
They have a guide on how to do it http://www.geoplugin.com/webservices/php for whoever wants the job.
You must first download the plugin class at www.geoplugin.com/webservices/php . and then here is the code : <?php require_once('geoplugin.class.php'); $geoplugin = new geoPlugin(); try { //locate the IP $geoplugin->locate(); echo "Country Name: {$geoplugin->countryName} <br />\n". "Country Code: {$geoplugin->countryCode} <br />\n". }catch($eror){ //to handle error echo " "; } ?> just save with any name of file in the same directory with the file goeplugin.class.php and then access it with the browser..
Dude, I think you are in the wrong section. People offer their services here or they chose to look for service providers by opening a thread. What you are doing is a contest and there is a whole new section for that. And no offense, if you can't do your assignments you got to offer better rates man, $7 wouldn't even buy us meals.
This $7 challenge is just a test to who is the talented PHP programmer here! I've stated clearly that you will be given a job offer once you complete the challenge. The real job offer will pay $100usd per edit on our client's website..
Well he said use less than 10 line of code... The correct code is: $array2 = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.$_SERVER['REMOTE_ADDR'])); echo $array2['geoplugin_countryCode']; I am from Lithuania so the country code I get is: LT
Everyone seems to be ignoring the 15 second timeout window. $rm_add = "www.geoplugin.net/php.gp?ip={$_SERVER['REMOTE_ADDR']}"; $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $rm_add ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt( $ch, CURLOPT_TIMEOUT, 15 ); $response = curl_exec( $ch ); curl_close ( $ch ); $geo = unserialize( $response ); var_dump( $geo ); Code (markup):
PHP Function <?php /** * Function to get contry code * * @param string $ip - Ip address * @param integer $waitTime - Maximum time to wait for request to be fullfilled * @return string */ function getCountryCode($ip, $waitTime = 15) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, sprintf("www.geoplugin.net/php.gp?ip=%s", $ip)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, $waitTime); $geoData = unserialize(curl_exec($ch)); curl_close($ch); return $geoData['geoplugin_countryCode']; } ?> Code (markup): Function Usage <?php echo "Country Code : " . getCountryCode($_SERVER['REMOTE_ADDR']); ?> Code (markup):
Thank you Savan, your entry was chosen as the best answer. Payment was already posted to your paypal account.
Wow that is funny considering he got the code right off of geoplugin's website. And your challenge clearly states a max execution time of 15 second which this clearly doesn't do. Well that just goes to show that your posting challenges that you don't even know the answers to. Good luck with your talent search.
<?php echo var_export(unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.$_SERVER['REMOTE_ADDR'])));?>
There is no error checking done in the script. Also the page will hang if geoplugin.net does not respond for any reason.
You shouldn't rely on a third-party API service, especially if you want to get the user's country for localization. Feel free to PM me if you want to use my library which relies on cached data to return the country of the user, no API meaning that it returns the result in the fraction of the second. (Not interested in the challenge, just providing some input)