473,405 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

IP to Country Problem

106 100+
Hi ,

i need to get the country of the visitor of the site so i downloaded a DB of all the countries and their corresponding IPs but not in Dotted format ,
but it fails to get my country although it's listed in the DB but seems the IP is not present in the DB ..
i convert the IP using ip2long() function which generates 9 numbers ALthough all the IPs in the DB for my country are 10 numbers so the script fails to show my Country ...anyone have an answer for this ??
Dec 23 '08 #1
11 1448
Atli
5,058 Expert 4TB
The format of the data you use in your search query must match the format of the data in your database, or the database will not return correct results (obviously).

Therefore, you must know how the data in your database is formatted so you can convert the IP address of your visitors into that format.

So the real question is: how is the data in the database formatted?
Some examples would be good.

Without that info there is little we can do to help you.
Dec 24 '08 #2
jessy
106 100+
Well, thats a sample of the CountryIp DB :
Expand|Select|Wrap|Line Numbers
  1. 1358400256,1358400511,AFGHANISTAN
  2. 3642070112,3642070127,AFGHANISTAN
  3. 3650609920,3650610175,AFGHANISTAN
  4. 3650610688,3650611455,AFGHANISTAN
  5. 1347305472,1347309567,ALBANIA
  6. 3252439552,3252439583,ALBANIA
and the ReadMe File Says i should transform the Visitors IP using ip2long Function and when i do that i get a nine numberIP while all my Countries listed IPs are 10 digits !!
Dec 24 '08 #3
Atli
5,058 Expert 4TB
Are you sure they are all 10 characters long?

According to my tests, all IP addresses starting with 58 or less will be 9 chars.
Parts of Japan should belong to that group. What does your DB say about that zone?

You should also note that the because PHP's integers are signed, some of the long values given by the ip2long function will result in negative values, which is probably not what you want to be using.

To get the actual unsigned long as a string, you can do something like:
Expand|Select|Wrap|Line Numbers
  1. $ulong = sprintf("%u", ip2long($ip));
  2.  
P.S.
I deleted the duplicate post you made.
Dec 24 '08 #4
jessy
106 100+
Yeah, You're Right Japan are 9 digits :
721420288,738197503,JAPAN
anyway, i cant seem to find my country :(

and Yes i Used this line exactly as you wrote :
$ip = sprintf("%u", ip2long($ip));
Dec 24 '08 #5
Atli
5,058 Expert 4TB
Your country isn't listed in the database?
I would call that a rather large oversight :)

Is there a change that there are parts of it missing?
How did you set it up?
Dec 24 '08 #6
jessy
106 100+
NO Sir :D
My Country is Listed But i Mean Listed in 10 Digits NOt 9 !!
I Began To Doubt My IP :)
i even checked it on Many Sites and Used an online Calculator to do that transformation thing
Dec 24 '08 #7
xNephilimx
213 Expert 100+
hi jessy.
I had the same problem, and another downside about downloading a db, is that you have to keep updating it if something changes.
I use this now geoPlugin
If you use curl (or even js), you can get info from their api, and it has a lot more and cool functionalities (like goelocation, for example -latitude, longitude-, so you can combine it with google/live/other maps).
Dec 24 '08 #8
Atli
5,058 Expert 4TB
In that case I would definitely not rely on that database to much.
Who knows how many other holes there are in the data.

You should give xNephilimx's idea a try
Dec 24 '08 #9
jessy
106 100+
Okay, I followed The Steps at GeoPlugin and made my domain activated and added the lines of the Js functions , but can you tell me how to call the country function

$countryName=geoplugin_countryName();
coz this seems not working with me

Thanks Alot

<sorry for the title its a mistake >
Dec 24 '08 #10
jessy
106 100+
Thank You So Much 'xNephilimx'

I Followed The Examples There and Everything is Working Great Now !
Dec 25 '08 #11
xNephilimx
213 Expert 100+
@jessy
Glad to read that!
I'm sorry I couldn't reply earlier, but I'm off any computers during weekends, XD
Dec 28 '08 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: abracad | last post by:
Hi Is there any (preferably free) PHP script that will identify the country of a visitor, thus allowing one page to be delivered to those from A, B and C, and another to those from X, Y and Z? ...
2
by: serena | last post by:
hi i am working on a project in asp.net which has a page with details about a user. on filling the city or the country i want to know the time in that city or country and display in a label. ...
2
by: Zyron | last post by:
Hello! I'm developing a web page that has a goal of providing personal content, which means that all information should be written in their own language. I'm about to finish my Geo targeting...
4
by: Susanne Christe | last post by:
Hi all, I know how to use System.Globalization.RegionInfo, but I have problems to get the Numeric Country Code like this here: http://www.atmajaya.ac.id/Weblinks/KodeNegara.html ISO-3166. ...
7
by: Lloyd Dupont | last post by:
from the IP of the request ?
3
by: Mark B | last post by:
I have a aspx form with a combobox drop-down to select 1 country from over 120 countries. On the next web page after that, I also have the same combobox so that the user can make a final...
10
by: Nospam | last post by:
I have a few javascripts. I would like to show a certain script based on the country ip of the viewer, how would I achieve this? is there html I could use to run the javascript based on the...
4
by: steve_barker333 | last post by:
Hi guys, I'm designing a web-site that will allow users to look up other people, based on certain criteria. The most important criterion is geographical location. I've managed to find a...
13
by: bushi | last post by:
hi everyone! i want to get the ipaddress,and the country name of a webpage visitor,using asp.Net(C#).if anyone knows about it,plz rply me. thanx in advance.
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.