PDO::ERRMODE_WARNING, PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")); } catch(PDOException $e) { echo $e->getMessage(); } if($_GET['search']){ ###print "Looking up " . $_GET['lookup'] . "
"; if(is_numeric(trim($_GET['search']))){ $zip = $_GET['search']; } if($zip){ # we received a zip code, so query all domains that match this zip # this method may also be used if we receive a city, state, etc - # the difference is we have to query a list of zip codes first } else { # we received a string, so attempt to reverse engineer that and find zip codes related to it } # end checking for zip or string # if there is a radius in the query, pull all zips within that radius & push them onto the ziplist array $radius = array_key_exists('radius', $_GET) ? $_GET['radius'] : null; if($radius){ # radius supplied, pull all results within the great circle distance $sth = $dbh->prepare("SELECT * FROM zips WHERE zip=? LIMIT 1"); $sth->execute(array($zip)); $row = $sth->fetch(PDO::FETCH_ASSOC); $sql = "SELECT *, ( 3959 * acos( cos( radians(" . $row['lat'] . ") ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(" . $row['lng'] . ") ) + sin( radians(" . $row['lat'] . ") ) * sin( radians( lat ) ) ) ) AS distance FROM zips HAVING distance < ? #ORDER BY distance"; $sth = $dbh->prepare($sql); $sth->execute(array($_GET['radius'])); foreach ($sth->fetchAll() as $row) { $ziplist[] = $row['zip']; } } $ziplist = array_unique($ziplist); if($ziplist){ $ziplist = "'" . join("','",array_filter($ziplist)) . "'"; } elseif($zip){ $ziplist = "'" . $zip . "'"; } if($ziplist){ $strict = array_key_exists('strict', $_GET) ? $_GET['strict'] : null; if($strict){ # we received strict mode toggle # so we limit domain results to this zip code only when there is also a matching phone number # OR the website only has 1 location result # default mode will return any fuzzy location match, regardless if there is 1 or 100 locations listed # strict mode: # pull list of area codes to match the list of zips # select domains, locations, phones as left joins # match where phone is like area code% or 1areacode% #SELECT * FROM `location` left join phone on location.wid=phone.wid WHERE zip='97239' and phone.phone like '503%' # select a list of area codes to work with # this can either be done for the exact zip code searched for # or if a radius is present, area codes for all zip codes within radius $sthc = $dbh->prepare("SELECT GROUP_CONCAT(area_codes SEPARATOR ',') as area_codes FROM zips WHERE zip IN (" . $ziplist . ")"); $sthc->execute(); $rowc = $sthc->fetch(PDO::FETCH_ASSOC); $area_codes = $rowc['area_codes']; $area_codes = explode(",",$area_codes); $area_codes = array_unique($area_codes); $area_codes = join("|",$area_codes); # build the query for strict locations $sql = "SELECT distinct domain,zip FROM `location` left join phone on location.wid=phone.wid left join domains on domains.wid=location.wid WHERE location.zip IN (" . $ziplist . ") AND domains.parent='0' and phone.phone regexp '^" . $area_codes . "' LIMIT 100"; # a future strict mod will be to not show domains that have many location matches .. in some cases spammers have 4000 or more locations listed but no phones, or just one 800 number, etc. # build the count query based on above $sthc = $dbh->prepare("SELECT COUNT(distinct domain) as total FROM location left join phone on location.wid=phone.wid left join domains on domains.wid=location.wid WHERE location.zip IN (" . $ziplist . ") AND domains.parent='0' and phone.phone regexp '^" . $area_codes . "'"); } else { # non strict, so run the normal queries $sql = "SELECT distinct domain,zip FROM location left join domains on domains.wid=location.wid WHERE location.zip IN (" . $ziplist . ") AND domains.parent='0' LIMIT 100"; # build the count query based on above $sthc = $dbh->prepare("SELECT COUNT(distinct domain) as total FROM location left join domains on domains.wid=location.wid WHERE location.zip IN (" . $ziplist . ") AND domains.parent='0'"); } #print $sql; $sth = $dbh->prepare($sql); $sth->execute(); foreach ($sth->fetchAll() as $row) { $domains[] = $row['domain']; } $domains = array_unique($domains); $count = count($domains); if($count>0){ if($count >= "100"){ # count the total domains that would have been shown... $sthc->execute(array()); $rowc = $sthc->fetch(PDO::FETCH_ASSOC); $total = $rowc['total']; } ###print "
Showing " . $count . " matching domains

"; foreach ($domains as $domain) { ###print $domain . "
"; $all_domains[] = $domain; } } } else { ###print "This domain is currently not indexed! "; } } else { # we received something to look up ###print "IP lookup syntax: w3metrics.com/example.com
"; ###print "Or: w3metrics.com/93.184.216.34
"; ###print "Use this tool to find known domains sharing an IP"; } ?> Geo Targeted Websites Demo

Geo-targeted websites demo

    PDO::ERRMODE_WARNING, PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")); } catch(PDOException $e) { echo $e->getMessage(); } $sthc = $dbh->prepare("select count(*) as count from location where zip=?"); $sthc->execute(array($_GET['search'])); $rowc = $sthc->fetch(PDO::FETCH_ASSOC); $count = $rowc['count']; $sth = $dbh->prepare("SELECT domains.wid,domains.domain,location.zip FROM location LEFT JOIN domains ON location.wid=domains.wid WHERE location.zip=? LIMIT 20"); $sth->execute(array($_GET['search'])); foreach ($sth->fetchAll() as $row){ $domain = $row['domain']; $title = $row['site_title']; $description = $row['description']; $sthc = $dbh->prepare("select primary_city, state, zip from zips where zip=?"); $sthc->execute(array($row['zip'])); $rowc = $sthc->fetch(PDO::FETCH_ASSOC); $zip = $rowc['zip']; $city = $rowc['primary_city']; $state = $rowc['state']; $location = $rowc['primary_city'] . ", " . $rowc['state'] . " " . $rowc['zip']; $wid = isset($wid) ? $wid : ''; $out[] = array( "result" => array( array( "wid" => "$wid", "domain" => "$domain", "zip" => "$zip", "city" => "$city", "state" => "$state", "page_title" => "$title", "page_description" => "$description" ) ) ); ?>


Results

Results for

Search is limited to 20 results

API Notes

Use the following information to access these search results programmatically

For more information visit the API docs

curl http://w3data.co/api/1000/search.php?zip=

json data will be returned: