I am running on an linux system, will it work on that?

Discuss GeoSelects' IP address to geographic location database component here.

Moderators: Moderators, GeobytesAdmins

I am running on an linux system, will it work on that?

Postby Adrian » Wed Dec 22, 2004 12:38 pm

Someone wrote:I am running on an Linux system, will it work on that?

If you are hosted in a LAMP (Linux, Apache, MySql, PHP) environment then we recommend that you use this script viewtopic.php?f=9&t=6815 to download, import, and maintain the GeoNetmap data instance within your MySql database. While you can not utilize the GeoServer ISAPI extension software that ships with GeoSelect on a non-windows server, this approach will provide you with SQL access to the raw IP address map data in to your own back-end database which you can access directly from your scripting environment.

In addition to this script, there is a sample PHP script for performing the actual IP to location look-up here - see the next post below.

In summery however, basically the steps are:
  1. Purchase a GeoSelect subscription
  2. Run the installation script that is provided here: viewtopic.php?f=9&t=6815
  3. Copy and paste the PHP script below (in the next post) in to your application

Someone wrote:... and what type of software do I have to install?
You won't need to install any special software - all you will need is your scripting language - like PHP or Perl, and a database to load the data into.
Last edited by Adrian on Mon Jan 21, 2008 10:18 am, edited 5 times in total.
Adrian
“When it absolutely, positively has to be there, try looking in your Spam folder.” - Adrian McElligott - July 2009
--
Have you tried the Local Search facility on the IP Locator Page yet?
User avatar
Adrian
Moderator
 
Posts: 970
Joined: Thu Nov 20, 2003 9:58 am

Postby Russell » Tue Jan 25, 2005 12:41 pm

The following code has been tested under PHP 4.3.10 and MySql 4.0.14-nt. This script retrieves either server variable _SERVER['HTTP_X_FORWARDED_FOR'] or $_SERVER['REMOTE_ADDR'], converts the returned IP Address into a "Class C" subnet and queries a MySql version of GeoNetMap (GeoSelects' database component) for geographic information.

Note: There is an equivalent post and sample for users using ASP and MS SQL server here: http://forums.geobytes.com/viewtopic.php?p=3274#3274

The only code you need to modify is supplying the credentials connecting to your database:
Code: Select all
$link = mysql_connect("SERVER_NAME", "USER_NAME", "PASSWORD")

You can view example queries and table relationships in our (GeoNet)Map Integration Guide on our support page at http://www.geobytes.com/Support.htm

Code: Select all
<html>
<?php
// Get the client's IP
$IpAddress;
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR']) && preg_match('/^[d.]+$/', $_SERVER['HTTP_X_FORWARDED_FOR']))
{
 $IpAddress = &$_SERVER['HTTP_X_FORWARDED_FOR'];

}
else
{
 $IpAddress = &$_SERVER['REMOTE_ADDR'];
}
// echo "IP Address: $IpAddress";

// Now get the SubnetAddress
list($o1,$o2,$o3,$o4) = explode(".",$IpAddress);
$IpAddress = $o1.'.'.$o2.'.'.$o3;
// echo "<br>SubnetAddress: $IpAddress";

// Connecting, selecting database
$link = mysql_connect("SERVER_NAME", "USER_NAME", "PASSWORD")
   or die("Could not connect : " . mysql_error());
//echo "<p>Connected successfully</p>";
mysql_select_db("geonetmap") or die("Could not select database");

// Performing SQL query
$query = "SELECT c.city, r.region, co.country
FROM cities AS c
JOIN subnets AS s on c.cityid=s.cityid
JOIN regions AS r on c.regionid=r.regionid
JOIN countries AS co on c.countryid=co.countryid
where s.subnetaddress='$IpAddress'";

//PRINT($query);
$result = mysql_query($query) or die("Query failed : " . mysql_error());

// Printing results in HTML
echo "<table border=0 bgcolor="#EBEBEB">n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
   echo "t<tr>n";
   foreach ($line as $col_value) {
       echo "tt<td>$col_value</td>n";
   }
   echo "t</tr>n";
}
echo "</table>n";

// Free resultset
mysql_free_result($result);

// Closing connection
mysql_close($link);
?>
</html>
Russell
Image it's the end of spam...
http://m.geobytes.com/
<geoselect><geoif geodefault>Special Welcome to folks from <geobytes city>, <geobytes country>.</geoif></geoselect>
User avatar
Russell
Moderator
 
Posts: 372
Joined: Mon Dec 08, 2003 9:05 am
Location: Brisbane, Australia

Postby Russell » Mon Jan 31, 2005 7:46 am

It is also worth noting Private Addresses (for more information see http://www.faqs.org/rfcs/rfc1918.html) are not in the subnets table and you will have to add a row/rows into the subnets table yourself every time you truncate and reimport the subnets table.

This would be useful if you are on the same network as your webserver as when you connect to your webservers' remote address will be a private address (which the subnets table doesn't have) and thus not return any geographic data.

I have created a dynamic SQL script (run at the database table subnets -not the flat text subnets.txt file) at http://forums.geobytes.com/user/pages/G ... sQuery.php
If we cannot locate your IP address (or you live in Santa Barbara) this script will be for the city "Santa Barbara, California, United States"

This is meant as a guide and reminder - there are other private addresses and you version of the query above would depend on your network setup.
Last edited by Russell on Mon Jan 31, 2005 8:11 am, edited 1 time in total.
Russell
Image it's the end of spam...
http://m.geobytes.com/
<geoselect><geoif geodefault>Special Welcome to folks from <geobytes city>, <geobytes country>.</geoif></geoselect>
User avatar
Russell
Moderator
 
Posts: 372
Joined: Mon Dec 08, 2003 9:05 am
Location: Brisbane, Australia

Postby Adrian » Mon Jan 31, 2005 7:59 am

Hi Russ,
Wouldn't you just use the localsubnets.txt file for this?
Adrian
“When it absolutely, positively has to be there, try looking in your Spam folder.” - Adrian McElligott - July 2009
--
Have you tried the Local Search facility on the IP Locator Page yet?
User avatar
Adrian
Moderator
 
Posts: 970
Joined: Thu Nov 20, 2003 9:58 am

Postby Russell » Mon Jan 31, 2005 8:02 am

Probably not as a linux server wouldn't run GeoSelect :P - unless im missing a way of opening the file through PHP etc.
[EDIT]One way to save from the hassle of running the script every import would be to import a localsubnets table with the same structure
Code: Select all
CREATE TABLE localsubnets (
   SubNetAddress varchar (11) NOT NULL ,
   Certainty smallint NULL ,
   CityId int NULL ,
   RegionId int NULL ,
   CountryId int NULL ,
   DmaId smallint NULL ,
   RegionCertainty smallint NULL ,
   CountryCertainty smallint NULL ,
   PRIMARY KEY(SubNetAddress)
   );
import
Code: Select all
LOAD DATA INFILE 'localsubnets.txt' INTO TABLE localsubnets
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\\r\\n' IGNORE 1 LINES;

and query using UNION:
Code: Select all
sql="SELECT c.city, r.region, co.country
FROM cities AS c
JOIN subnets AS s on c.cityid=s.cityid
JOIN regions AS r on c.regionid=r.regionid
JOIN countries AS co on c.countryid=co.countryid
where s.subnetaddress='$IpAddress' 
UNION
SELECT c.city, r.region, co.country
FROM cities AS c
JOIN localsubnets AS ls on c.cityid=ls.cityid
JOIN regions AS r on c.regionid=r.regionid
JOIN countries AS co on c.countryid=co.countryid
where ls.subnetaddress='$IpAddress'";
[/EDIT]
Russell
Image it's the end of spam...
http://m.geobytes.com/
<geoselect><geoif geodefault>Special Welcome to folks from <geobytes city>, <geobytes country>.</geoif></geoselect>
User avatar
Russell
Moderator
 
Posts: 372
Joined: Mon Dec 08, 2003 9:05 am
Location: Brisbane, Australia

Postby Russell » Sat Jun 25, 2005 1:23 pm

The more I think about this - the more I think it is very possible to use your localsubnets.txt file in your script. You would simply have to open it like you would normally open a file in your server-side language of choice. Obviously if using something as big as subnets table would take a hit on the server - however you would think that the localsubnets.txt files would be relativly small (<> 10 or 20 lines etc).

As usual with life, for any given problem there is often more than one soloution.

If anyone is interested I can spend the time to look into this.
Russell
Image it's the end of spam...
http://m.geobytes.com/
<geoselect><geoif geodefault>Special Welcome to folks from <geobytes city>, <geobytes country>.</geoif></geoselect>
User avatar
Russell
Moderator
 
Posts: 372
Joined: Mon Dec 08, 2003 9:05 am
Location: Brisbane, Australia

Re: I am running on an linux system, will it work on that?

Postby sunnsky » Thu Dec 27, 2007 4:17 am

In summery however, basically the steps are:

Purchase a GeoSelect subscription
Download a copy of the map data
Import the map data using the scripts at http://epicenter.geobytes.com/MySqlInstructions.htm
Copy and paste the PHP script below (in the next post) in to your application


Is there any information on exactly where in our application the PHP script referred to in bold above, should be copied and pasted?

I'm using Dolphin ( a php based community script) we managed to create and successfully populate our Geobytes database, and were ready to try the script as a test. We tried a couple of things without results. Please advise if you would be so kind. :)
sunnsky
 
Posts: 2
Joined: Thu Dec 27, 2007 4:09 am

Postby Adrian » Thu Dec 27, 2007 4:31 am

Hi sunnsky,
I am not familiar with 'Dolphin' and perhaps because of this I may be misunderstanding your question, but wouldn't you just insert the above code in your application where you require the IP localisation data. I mean wherever it is, in your code that you need to know the location of the visitor, you would insert the above code to retrieve the location data from your database.
So it would be inserted into your existing php code.
Sorry if I have misunderstood your question, but please do let me know if I can assist further.
Adrian
“When it absolutely, positively has to be there, try looking in your Spam folder.” - Adrian McElligott - July 2009
--
Have you tried the Local Search facility on the IP Locator Page yet?
User avatar
Adrian
Moderator
 
Posts: 970
Joined: Thu Nov 20, 2003 9:58 am

Postby sunnsky » Thu Dec 27, 2007 4:47 am

Thanks for the reply. I don't know exactly what we should see it as result of that code. But no matter where we insert it in our application we get what you'll see here: http://realpeoplenearby.com/index.php the first module below the flash animation on the right is called location code.
What do you make of it?
Could you point me to an example of exactly what we should see as result of that code being properly inserted?
sunnsky
 
Posts: 2
Joined: Thu Dec 27, 2007 4:09 am

Postby Adrian » Thu Dec 27, 2007 5:19 am

sunnsky wrote:...no matter where we insert it in our application we get what you'll see here: http://realpeoplenearby.com/index.php the first module below the flash animation on the right is called location code.
What do you make of it?
OK, the server is not executing the script. The script is PHP code and needs to be insert as you would any other php script.
Do you have the facility to insert php script in to your pages - do you know how to read data from your mysql database. Because that is all that this script is doing - it is just executing a SQL query and writing the out put to the current page. So wherever it is inserted (and executed) it will just out-put the viewer's City, Region (State), and Country.
As I said earlier, I am not familiar with 'Dolphin' but I just had a quick browse through http://www.expertzzz.com/dolphin and it appears that you would need to install the code as a plug in. In any case, you will need to find out how to read data from a database within your 'Dolphin' environment - it is quite likely that there is already a 'Dolphin' plug-in available to do this, and once you find it then all you will need to do is use it to execute the SQL query from the above code.

Unfortunately I can't help you find the 'Dolphin' database plug-in (if it exists) but once you do find out how to read from a database, then I can assist you with the SQL query - if needed, so please let me know know if I can assist further.
Adrian
“When it absolutely, positively has to be there, try looking in your Spam folder.” - Adrian McElligott - July 2009
--
Have you tried the Local Search facility on the IP Locator Page yet?
User avatar
Adrian
Moderator
 
Posts: 970
Joined: Thu Nov 20, 2003 9:58 am

Re:

Postby evanjones246 » Thu Feb 16, 2012 9:54 pm

Hi, I am getting the same thing when I insert code into my application. Did you find out what it should look like, and if so, could you point me in the right direction? Thanks!
sunnsky wrote:Thanks for the reply. I don't know exactly what we should see it as result of that code. But no matter where we insert it in our application we get what you'll see here:Web Hostinghttp://realpeoplenearby.com/index.phpSmall Business Web Hostingthe first module below the flash animation on the right is called location code.
What do you make of it?
Could you point me to an example of exactly what we should see as result of that code being properly inserted?
evanjones246
 
Posts: 1
Joined: Thu Feb 16, 2012 9:48 pm

Re: I am running on an linux system, will it work on that?

Postby swingate » Fri Sep 21, 2012 1:38 pm

Hi, the post and sample listed below under 'Note:' is not working for me. (ASP user).

Russell wrote:The following code has been tested under PHP 4.3.10 and MySql 4.0.14-nt. This script retrieves either server variable _SERVER['HTTP_X_FORWARDED_FOR'] or $_SERVER['REMOTE_ADDR'], converts the returned IP Address into a "Class C" subnet and queries a MySql version of GeoNetMap (GeoSelects' database component) for geographic information.



Note: There is an equivalent post and sample for users using ASP and MS SQL server here: viewtopic.php?p=3274#3274



The only code you need to modify is supplying the credentials connecting to your database:

Code: Select all
$link = mysql_connect("SERVER_NAME", "USER_NAME", "PASSWORD")

You can view example queries and table relationships in our (GeoNet)Map Integration Guide on our support page at http://www.geobytes.com/Support.htm

Code: Select all
<html>
<?php
// Get the client's IP
$IpAddress;
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR']) && preg_match('/^[d.]+$/', $_SERVER['HTTP_X_FORWARDED_FOR']))
{
 $IpAddress = &$_SERVER['HTTP_X_FORWARDED_FOR'];

}
else
{
 $IpAddress = &$_SERVER['REMOTE_ADDR'];
}
// echo "IP Address: $IpAddress";

// Now get the SubnetAddress
list($o1,$o2,$o3,$o4) = explode(".",$IpAddress);
$IpAddress = $o1.'.'.$o2.'.'.$o3;
// echo "<br>SubnetAddress: $IpAddress";

// Connecting, selecting database
$link = mysql_connect("SERVER_NAME", "USER_NAME", "PASSWORD")
   or die("Could not connect : " . mysql_error());
//echo "<p>Connected successfully</p>";
mysql_select_db("geonetmap") or die("Could not select database");

// Performing SQL query
$query = "SELECT c.city, r.region, co.country
FROM cities AS c
JOIN subnets AS s on c.cityid=s.cityid
JOIN regions AS r on c.regionid=r.regionid
JOIN countries AS co on c.countryid=co.countryid
where s.subnetaddress='$IpAddress'";

//PRINT($query);
$result = mysql_query($query) or die("Query failed : " . mysql_error());

// Printing results in HTML
echo "<table border=0 bgcolor="#EBEBEB">n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
   echo "t<tr>n";
   foreach ($line as $col_value) {
       echo "tt<td>$col_value</td>n";
   }
   echo "t</tr>n";
}
echo "</table>n";

// Free resultset
mysql_free_result($result);

// Closing connection
mysql_close($link);
?>
</html>
swingate
 
Posts: 1
Joined: Fri Sep 21, 2012 1:30 pm

Re: I am running on an linux system, will it work on that?

Postby Adrian » Mon Sep 24, 2012 1:30 pm

swingate wrote:Hi, the post and sample listed below under 'Note:' is not working for me. (ASP user).

OK - I am keen to help, but would there be any chance of giving us just a hint of what error message you might be receiving, and perhaps just a clue to what your operating environment might be, or even at what part of the process that things started to turn pear shaped?
Adrian
“When it absolutely, positively has to be there, try looking in your Spam folder.” - Adrian McElligott - July 2009
--
Have you tried the Local Search facility on the IP Locator Page yet?
User avatar
Adrian
Moderator
 
Posts: 970
Joined: Thu Nov 20, 2003 9:58 am


Return to GeoNetMap

Who is online

Users browsing this forum: No registered users and 1 guest