Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6002463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:58:55+00:00 2026-05-23T00:58:55+00:00

I am trying to use the country detection by IP, an API from http://www.hostip.info/use.html

  • 0

I am trying to use the country detection by IP, an API from http://www.hostip.info/use.html

So if you put in your browser something like:
http://api.hostip.info/country.php?ip=12.24.25.26

then the page will write “US”…

Now my question is how can I use this in a IF ELSE lopp in my php code? I think I have to parse that HTML page, but at the moment I have no clue, some help would be appriciated!

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T00:58:56+00:00Added an answer on May 23, 2026 at 12:58 am

    Since that page does not output anything other than the country code, there is no parsing required. A simple check on the returned HTML will do it.

    <?php
    $ip = '12.24.25.26';
    $country = file_get_contents('http://api.hostip.info/country.php?ip='.$my_ip); // Get the actual HTML
    
    if($country === "US") {
        echo "It is US";
    } else {
        echo "It is not US. It is " . $country;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
I'm trying to use an external site's API to get users IP info (country,
I'm trying to use a paypal library form I found here: http://www.amplio.ch/blog/web-development/paypal-integration-to-codeigniter/ However, I'm
i'm trying use facebook API to upload photo in my fan page. I downloaded
Trying to use Powershell to script the removal of specific custom errors from an
I am trying to use the MaxMind GeoLite Country database on the Google App
I am trying to use hostip in order to save to DB user's general
i am trying to use ip2c to get country codes based on the ip
I'm trying to use the SUM function to count rows from 3 tables, which
I was trying to use $.getJSON to go through the json arrays from the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.