1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Buying Another harder PHP programming challenge $7USD

Discussion in 'Programming' started by Manald, Oct 8, 2014.

  1. #1
    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
     
    Manald, Oct 8, 2014 IP
  2. strike2867

    strike2867 Member

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #2
    They have a guide on how to do it http://www.geoplugin.com/webservices/php for whoever wants the job.
     
    strike2867, Oct 8, 2014 IP
  3. Manald

    Manald Well-Known Member

    Messages:
    809
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    140
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #3
    Please post the response here. Don't sent me any PMs.
     
    Manald, Oct 8, 2014 IP
  4. 14web_net

    14web_net Greenhorn

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #4
    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..
     
    14web_net, Oct 8, 2014 IP
  5. Valkyrie™

    Valkyrie™ Well-Known Member

    Messages:
    164
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    110
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #5
    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.
     
    Valkyrie™, Oct 8, 2014 IP
  6. Manald

    Manald Well-Known Member

    Messages:
    809
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    140
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #6
    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..
     
    Manald, Oct 8, 2014 IP
  7. Savan

    Savan Member

    Messages:
    45
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    48
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #7
    Savan, Oct 8, 2014 IP
  8. Feral

    Feral Active Member

    Messages:
    70
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    68
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #8
    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):
     
    Feral, Oct 8, 2014 IP
  9. ChiragKalani

    ChiragKalani Active Member

    Messages:
    41
    Likes Received:
    2
    Best Answers:
    3
    Trophy Points:
    73
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #9
    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):
     
    ChiragKalani, Oct 12, 2014 IP
    coldcoder likes this.
  10. Manald

    Manald Well-Known Member

    Messages:
    809
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    140
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #10
    Thank you Savan, your entry was chosen as the best answer. Payment was already posted to your paypal account.
     
    Manald, Oct 12, 2014 IP
  11. Feral

    Feral Active Member

    Messages:
    70
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    68
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #11
    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.
     
    Feral, Oct 12, 2014 IP
  12. ashishkg

    ashishkg Active Member

    Messages:
    233
    Likes Received:
    8
    Best Answers:
    3
    Trophy Points:
    68
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #12
    ashishkg, Oct 13, 2014 IP
  13. Manald

    Manald Well-Known Member

    Messages:
    809
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    140
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #13
    Manald, Nov 4, 2014 IP
  14. SentoWeb

    SentoWeb Active Member

    Messages:
    189
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
    Digital Goods:
    3
    As Seller:
    100% - 2
    As Buyer:
    100% - 0
    #14
    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)
     
    SentoWeb, Nov 8, 2014 IP