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 860351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:48:18+00:00 2026-05-15T08:48:18+00:00

I’ve downloaded WIPmania’s worldip table from http://www.wipmania.com/en/base/ — the table has 3 fields and

  • 0

I’ve downloaded WIPmania’s worldip table from http://www.wipmania.com/en/base/ — the table has 3 fields and around 79k rows:

  • startip // example: 3363110912
  • endip // example: 3363112063
  • country // example: AR (Argentina)

So, lets suppose i’m in Argentina and my IP address is: 200.117.248.17

1) I use this function to convert my ip to long

function ip_address_to_number($ip) {
    if(!$ip) {
        return false;
    } else {
        $ip = split('\.',$ip);
        return($ip[0]*16777216 + $ip[1]*65536 + $ip[2]*256 + $ip[3]);
    }
}

2) I search for the proper country code by matching the long converted ip:

$sql = 'SELECT * FROM worldip WHERE '.ip_address_to_number($_SERVER['REMOTE_ADDR']).' BETWEEN startip AND endip';

which is equivalent to:
SELECT country FROM worldip WHERE 3363174417 BETWEEN startip AND endip (benchmark: Showing rows 0 – 0 (1 total, Query took 0.2109 sec))

Now comes the real question.

What if another bunch of argentinian guys also open the website and they all have these ip addresses:

  • 200.117.248.17
  • 200.117.233.10
  • 200.117.241.88
  • 200.117.159.24

Since i’m caching all the sql queries; instead of matching EACH of the ip queries in the database, would it be better (and right) just to match the 2 first sections of the ip by modifying the function like this?

function ip_address_to_number($ip) {
    if(!$ip) {
        return false;
    } else {
        $ip = split('\.',$ip);
        return($ip[0]*16777216 + $ip[1]*65536);
    }
}

(notice that the 3rd and 4th splitted values of the IP have been removed).

That way instead of querying these 4 values:

  • 3363174417
  • 3363170570
  • 3363172696
  • 3363151640

…all i have to query is: 3363110912 (which is 200.117.0.0 converted to long).

Is this right? any other ideas to optimize this process?

  • 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-15T08:48:19+00:00Added an answer on May 15, 2026 at 8:48 am

    Do you absolutely have to use WIPmania? if not, Maxmind offers an open source solution: http://www.maxmind.com/app/geolitecountry. The advantage is that it’s a binary file, and there’s a PHP extension (you’d have to compile it ans install it). Used it on a couple of projects, the lookups are blazing fast. You can get the PCL extension here:
    http://pecl.php.net/package/geoip

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
In my XML file chapters tag has more chapter tag.i need to display chapters
I have a text area in my form which accepts all possible characters from

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.