Jun 19 2009 Programming

Have you ever come across a webpage with an image of some girl with some provocative nickname claiming to be from your city? Here's how that works.  

They use the GeoIP database.
Here's a PHP interface I made for it.
You can see it in action → here


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Location Lookups</title>
<meta name="keywords" content="'web 2.0' ">
<meta name="author" content="E. Dziewa">
<meta name="description" content="white page with dark letters">
<link rel="stylesheet" type="text/css" href="lookup.css">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<div style="width: 60%">

<?php
if ( (!$_POST) && (empty($_GET['l'])) ) $lookup = $_SERVER['REMOTE_ADDR'];
elseif ( !empty($_GET['l']) ) $lookup = $_GET['l'];
else $lookup = $_POST['lookup'];

$lookup = trim($lookup); // strip whitespace
if ( preg_match( '/dziewa/', $lookup ) ) {
    $lookup = 'passaic-city.k12.nj.us'; // resolves to passaic
    $flag = 1;
}
elseif (
    ( !preg_match( '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $lookup ) ) &&
    ( !preg_match( '/^[A-Za-z0-9._-]+$/', $lookup ) ) ) {
        exit("We accept IP addresses, and domain names only.");
}
elseif ( preg_match( '/^192\.168\./', $lookup ) ) {
    if ( $_SERVER['REQUEST_METHOD'] != 'GET)
        exit("Sorry we don't look up private network addresses.");
    else {
        $flag = 1;
        $lookup = 'passaic-city.k12.nj.us'; // resolves to passaic
    }
}
// replace the #'s with your own ip #'s
elseif ( preg_match( '/###\.###\.###\.###/', $lookup ) ) { // your own ip
    // replace with what you'd like to be looked up as
    $lookup = '69.116.176.111'; // garfield
    $flag = 1;
}

if ($flag) { // looking for info on us
    if ( !empty($_POST['lookup']) ) {
        echo '
        <table width="100%" border="0"><tr><td class="black_head">
        <span class="header"> Results on '.$_POST['lookup'].'</span>
        </td></tr><tr><td><p>';
    }
    elseif ( !empty($_GET['l']) ) {
        echo '
        <table width="100%" border="0"><tr><td class="black_head">
        <span class="header"> Results on '.$_GET['l'].'</span>
        </td></tr><tr><td><p>';
    }
    else { 
        echo '
        <table width="100%" border="0"><tr><td class="black_head">
        <span class="header"> Results on '.$lookup.'</span>
        </td></tr><tr><td><p>';
    }
}
else {
    echo '
    <table width="100%" border="0"><tr><td class="black_head">
    <span class="header"> Results on '.$lookup.'</span>
    </td></tr><tr><td><p>';
}
$types = array(
    'continent_code=> 'Continent',
    'country_name=> 'Country',
    'region'       => 'Region',
    'city'         => 'City',
    'postal_code'  => 'Postal Code',
    'area_code'        => 'Area Code',
    'longitude'        => 'Longitude',
    'latitude'     => 'Latitude'
);
$conts = array(
    'NA'   => 'North America',
    'EU'   => 'Europe',
    'SA'   => 'South America',
    'AS'   => 'Asia',
    'AF'   => 'Africa',
    'OC'   => 'Australia',
    'AN'   => 'Antarctica'
);

$rec = geoip_record_by_name("$lookup");
if ( empty($rec['continent_code']) ) echo "<br>No data found<br>";
else {
    echo "<table border=\"0\" width=\"80%\" style=\"margin-left: 40px\">\n";

    foreach ( $types as $testme => $title ) {
        if ( !empty($rec[$testme]) ) {
            if ( ($testme == 'continent_code') && ( !empty($conts[$rec[$testme]]) ) ) {
                echo "\t<tr><td class=\"desc\">$title</td><td class=\"desc\">".$conts[$rec[$testme]]."</td></tr>\n";
            }
            else {
                echo "\t<tr><td class=\"desc\">$title</td><td class=\"desc\">$rec[$testme]</td></tr>\n";
            }
        }
    }

    $a = geoip_time_zone_by_country_and_region($rec['country_code'], $rec['region']);
    if ($a) {
        echo "\t<tr><td class=\"desc\">Time Zone</td><td class=\"desc\">$a</td></tr>\n";
    }

    $ourtime = date_default_timezone_get();
    $theirtime = date_default_timezone_set( $a );
    if ( $theirtime ) {
        echo "\t<tr><td class=\"desc\">Current Time</td><td class=\"desc\">".date('H:i')."</td></tr>\n";
        date_default_timezone_set( $ourtime );
    }

    echo "</table><br>";
}
?>

</td></tr></table>
    <form action="lookup.php" method="post">
<table width="100%" border="0"><tr><td class="black_tail">&nbsp;
Lookup another:
    <input type="text" class="ff" name="lookup" size="20" maxlength="40">
            <input type="submit" class="butsty" name="submit" value="Go!">
        </td></tr></table>
</form></div><div style="font-size: 1px">
"This product includes GeoLite data created by MaxMind, available from http://www.maxmind.com/"
</div></html>


you can for instance append l=55.66.77.88 to the url for linking. One day I'm going to expand this to include some other location relevant information. Someone suggested google maps, I'm thinking weather, local news, time to get there from here.


Download

   
Comments
Jun 23 2009
Comment #1 posted by Katy at 11:33 pm

Pretty nice post. I just found your blog and wanted to say
that I have really enjoyed browsing your blog posts. Anyway
I'll be subscribing to your blog and I hope you write again soon!

Mar 15 2010
Comment #2 posted by Abhijeet at 7:24 am

This is very nice. easy to understand and effective geo location tool. Thanks Eric :)

Dec 30 2010
Comment #3 posted by vivek at 1:46 am

this can be very useful script, thanks eric

Jun 23 2014
Comment #4 posted by Ameliavqg at 8:36 am

If you prefer decent, Coziness together with budget oakley sunglasses for guys, Brides, And kids; Occhialis is best search engine optimization supplier using model glasses. Select from big companies, , For instance, beam prohibition, Louis Vuitton, oakley, Chanel, Cartier plus more, Issues businesses in the usa and even england. sunglasses listen to a huge role in shielding the eyes by way of possibly damaging ultra violet rays. This process disguised. form of one's only provides the sort of the rays which may damage the eye area if it is overexposed.

Even so women continually use a tendency to copy a woman and here it's rather a mistake even though will attempt continue along with the renowns when purchasing sunglasses. A lot of such glasses tend to a low priced way to choose the luxurious mode brandnames from other brands inform, Prada, Beam prohibition and so on. It was very beneficial and i also enhanced all of often the very sort and consequently content uniquely unique them back as some agency above this type of yes.

Sabre perception has a collection of accessories where it tap out special, Clothing trendy combined with selection. Whether your goal is something common, Current fashions, Otherwise legendary, They offer it. Counterfeited oakley sunglasses are the most effective known brands of top quality in addition to the luxury sunglasses. , The particular eye glasses products carry granted many video to cheap oakley sunglasses suitable to receive caller to make. It's about time considering out bank account to put on few of trim with oakley sunglasses defend regarding each and every little brown view now to see pieces truly that year. As you move the glasses market is filled with snap within sunglasses, You can come up folks unhampered.

In addition, This kind of glasses not really certified or a developed that by oakley sunglasses . They are the same original oakley any way you like but are in fact patterns are sometimes made. They are purchased at an expense within on the original one as well as, created illegitimately. Inknown to be with her tv set franchise, Ellie Kardashian is the most effective excitement cal. king. Lindsay, In addition to predicament a queen that her, Tend to experience Chanel yet Gucci his or her fundamental variety of sunglasses.

Nov 4 2015
Comment #5 posted by GeDit at 9:51 am

??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

??????2011??????“????”??????1?20????????????????“??????”???????????????????10?8??2015????????????????????????????CEO???????????????????????

?????????????????????????????????????????????????????(CLIG)??????????????????????????????????????????????????????????

?????????2016?????????????(NIH)????????????(FDA)????????????????(ONC)????2.15?????????????????????

???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

??????????????????????????????????????????????????????????????????????????????????????????1980 ?????????2001 ???????????????????????2007 ?????????????????????????????????????Illumina ?????????2007 ??????????????????1000?????????1000 ??? ??Illumina ???????NGS(??????)??????????200 ??????????????????????????15%??????????????????????????120?????????Illumina????????????Genalyte, Centrillion????????

????????????????????????????????????????????????????????????????????????????????????????????????????????

???????????????????(The Chinese Finance Association, TCFA) ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

?????????????????????????????????????????????????????????????????????????????

Comments for this entry available via RSS.
Comment Area
Your Name
Your Email (will not be published)
Your Website
Your Comment
Profanity is Prohibited
eric.dziewa.com is running WordPress.
WhiteSpace theme designed by E. Dziewa.
All content © E. Dziewa.
Thanks for stopping by.