Cloudron makes it easy to run web apps like WordPress, Nextcloud, GitLab on your server. Find out more or install now.


Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Bookmarks
  • Search
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

Cloudron Forum

Apps - Status | Demo | Docs | Install
  1. Cloudron Forum
  2. IP2Location
  3. Code snippet ?

Code snippet ?

Scheduled Pinned Locked Moved Solved IP2Location
3 Posts 2 Posters 1.5k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • timconsidineT Online
    timconsidineT Online
    timconsidine
    App Dev
    wrote on last edited by
    #1

    GeoIP is very interesting to run some checks on visitor location (to deliver customised content).

    Just wondering if there is a code snippet to extract the country from the results returned.

    Indie app dev, scratching my itches, lover of Cloudron PaaS, communityapps.appx.uk

    murgeroM 1 Reply Last reply
    0
    • timconsidineT timconsidine

      GeoIP is very interesting to run some checks on visitor location (to deliver customised content).

      Just wondering if there is a code snippet to extract the country from the results returned.

      murgeroM Offline
      murgeroM Offline
      murgero
      App Dev
      wrote on last edited by
      #2

      @timconsidine Since the output from the api is just json encoded you can take the output in a variable and parse it:

      this example is PHP of course:

      <?php
      
      //google.com IP for mid-west US:
      $ip = "142.251.32.14";
      
      //Get string from API URL then convert the json output to PHP obj
      $geoip = file_get_contents("https://geoip.example.com/json?ip=$ip");
      $geoip = json_decode($geoip, true);
      
      //Output Country in string:
      echo "The registered country of the IP $ip is ".$geoip['registered_country']['names']['en']."\r\n";
      echo "Also, you can grab the country name via ['country']['names']['en']: ".$geoip['country']['names']['en']."\r\n";
      ?>
      

      --
      https://urgero.org
      ~ Professional Nerd. Freelance Programmer. ~

      timconsidineT 1 Reply Last reply
      3
      • murgeroM murgero

        @timconsidine Since the output from the api is just json encoded you can take the output in a variable and parse it:

        this example is PHP of course:

        <?php
        
        //google.com IP for mid-west US:
        $ip = "142.251.32.14";
        
        //Get string from API URL then convert the json output to PHP obj
        $geoip = file_get_contents("https://geoip.example.com/json?ip=$ip");
        $geoip = json_decode($geoip, true);
        
        //Output Country in string:
        echo "The registered country of the IP $ip is ".$geoip['registered_country']['names']['en']."\r\n";
        echo "Also, you can grab the country name via ['country']['names']['en']: ".$geoip['country']['names']['en']."\r\n";
        ?>
        
        timconsidineT Online
        timconsidineT Online
        timconsidine
        App Dev
        wrote on last edited by
        #3

        @murgero wonderful, thank you !
        PHP is great !

        Indie app dev, scratching my itches, lover of Cloudron PaaS, communityapps.appx.uk

        1 Reply Last reply
        1

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Bookmarks
        • Search