• Welcome to WebsiteBaker Community Forum. Please log in or sign up.
Welcome, Guest
News
Support WebsiteBaker
Your donations will help to:
PayPal
  • Pay for our dedicated server
  • Pay for domain registration
  • and much more!
You can donate by clicking on the button below.

Geolocation of Users

Started by markherrmann, October 08, 2021, 06:45:08 PM  ( Read 8,671 times )

markherrmann

Hi, im Rahmen einer Benutzerkontrolle habe ich in meinem Webprojekt mittels Droplet unter anderem eine geografische Zuordnung der User auf Basis deren IP-Adresse eingebaut. Ich lasse Länder, aus denen nur Spam ins Kontaktformular geschrieben wird gar nicht mehr auf meine Inhalte.
PS. Die Möglichkeiten Honeypot's oder weiterer Kontrollen (Laufzeit der UI-Eingaben) nutze ich zusätzlich im Formular.

Hier ein einfacher Code unter Nutzung eines Dienstleisters.
Da dieser gratis ist frage ich nicht jeden Request ab sondern speichere jeden Request mit Verfalldatum in Tabelle (now_online) ist er neu Frage ich ab, ist er bekannt oder verfallen dann nicht.

Das hat den Vorteil das der Fremde Dienst nicht bei jedem Seitenaufbau benutzt werden muss (Seitenladezeiten liegen so zwischen ca. 0,003 ms und 0,480 ms bei Nutzern aus Chicago US)

Anbei der rauskopierte Code (nicht elegant, aber als Anregung für andere gedacht):
function droplet_loadWebPage($url, $postdata="") {
$agent = WEBSITE_TITLE."_myAgent_1.0.0";
       
$header[] = "Accept: text/vnd.wap.wml,*.*";
       
$ch = curl_init($url);
       if (
$ch) {
curl_setopt($ch,    CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,    CURLOPT_USERAGENT, $agent);
curl_setopt($ch,    CURLOPT_HTTPHEADER, $header);
curl_setopt($ch,    CURLOPT_FOLLOWLOCATION, 1);
if (isset($postdata) && $postdata != "") {
curl_setopt($ch,    CURLOPT_POST, 1);
curl_setopt($ch,    CURLOPT_POSTFIELDS, $postdata);
} // end if isset
$tmp = curl_exec ($ch);
curl_close ($ch);
} // end if $ch
return $tmp;
unset (
$tmp);
}
// droplet_loadWebPage

// Benutzung eines OnlineDienstes... IP->LOCAL (db-ip.com)
$temp_local["inspect_ip"] = 'http://api.db-ip.com/v2/free/'.$out["ip"];
$temp_local["ip2local_info"] = droplet_loadWebPage($temp_local["inspect_ip"]);
$temp_local["json_object"] = json_decode($temp_local["ip2local_info"]);
if (!isset(
$temp_local["json_object"]->{'continentCode'})) {
$out["kontinent_id"] = '';
$out["kontinent_name"] = '';
$out["land_id"] = '';
$out["land_name"] = '';
$out["bundesland"] = '';
$out["stadt"] = '';
} else {
$out["kontinent_id"] = $temp_local["json_object"]->{'continentCode'};
$out["kontinent_name"] = $temp_local["json_object"]->{'continentName'};
$out["land_id"] = $temp_local["json_object"]->{'countryCode'};
$out["land_name"] = droplet_german_code2land($out["land_id"]);
// $out["land_name"] = $temp_local["json_object"]->{'countryName'};
$out["bundesland"] = $temp_local["json_object"]->{'stateProv'};
$out["stadt"] = $temp_local["json_object"]->{'city'};
}
// end if isset
return $out;
}
// droplet_getUserinformation


    \n\n