<?php
# Aufruf mit 'cidlookup.php?cid=49301234567'
# Liefert Name zurueck
$name = "";
$details = "";
if ($cid == "") {
$name = "anonymer Anrufer";
$details = "Keine Details";
} else {
$cid = preg_replace("|^49|s","0",$cid);
# reverse Lookup via www.dasoertliche.de
$host = 'www3.dasoertliche.de';
$path = '/Controller';
$data = 'form_name=search_inv&la=de&page=5&context=4&action=43&buc=&ph=' . rawurlencode ($cid);
$fp = fsockopen ($host, 80);
if (!$fp)
$name = "Fehler in Abfrage $errstr ( $errno)";
else {
$result = "";
fputs ($fp, 'POST ' . $path . ' HTTP/1.1' . "\r\n");
fputs ($fp, 'User-Agent: Mozilla/4.0 Compatible' . "\r\n");
fputs ($fp, 'Host: ' . $host . "\r\n");
fputs ($fp, 'Content-type: application/x-www-form-urlencoded' . "\r\n");
fputs ($fp, 'Content-length: ' . strlen ($data) . "\r\n");
fputs ($fp, 'Connection: close' . "\r\n\r\n");
fputs ($fp, $data);
while (!feof($fp))
$result .= fgets($fp, 128);
fclose ($fp);
}
# Name und Anschrift herausfischen
$reg_name = '/class="preview" onclick="return logDetail[(].+[)]"><span class="">([^&]*)/';
$reg_details = '/<div class="strasse">\W*([^<]*)<span class="">([^<]*)/m';
if (preg_match ($reg_name, $result, $matches))
$name = str_replace (' ', ' ', $matches[1]);
$name = ltrim($name);
if (preg_match ($reg_details, $result, $matches2))
$details = str_replace (' ', ' ', $matches2[1]);
$details = "$details $matches2[2]";
$details = str_replace (' ', ' ', $details);
$details = str_replace ('nbsp', ' ', $details);
$details = str_replace (' ', ' ', $details);
$details = ltrim($details);
if ($name == "") {
if (preg_match ('/war leider nicht erfolgreich/', $result, $matches)) {
$name = "Telefonnummer $cid";
$details = "Kein Eintrag";
}
}
}
print utf8_encode($name) ." . ". utf8_encode($details);
# print "$name . $details";
?>