DLP's Google Visit Counter funktioniert nicht richtig

Allgemeiner Support zum phpBB 2 Board und phpBB 2 Modifikationen
Forumsregeln
Auch wenn hier der Support für phpBB 2 weiterhin aufrecht erhalten bleibt, weisen wir darauf hin, dass das phpBB 2 nicht mehr offiziell unterstützt und weiterentwickelt wird!
Antworten
Benutzeravatar
karstenkurt
Beiträge: 597
Registriert: Do 31.Mär, 2005 20:20
Kontaktdaten:

DLP's Google Visit Counter funktioniert nicht richtig

Beitrag von karstenkurt »

Hallo,

der o.g. Mod funktioniert bei mir nicht richtig. Folgender Code wurd in die page_header eingefügt

Code: Alles auswählen

//
// Dr DLP's Google Visit Counter MOD
//
$google_visit_counter = $board_config['google_visit_counter'];

$tmp_list = explode(".", $REMOTE_ADDR);
if (($tmp_list[0] == "64" && $tmp_list[1] == "68" && $tmp_list[2] == "82") || ($tmp_list[0] == "216" && $tmp_list[1] == "239" && $tmp_list[2] == "46"))
{
	$sql = "UPDATE " . CONFIG_TABLE . "
			SET config_value = '" . ($google_visit_counter + 1) . "'
			WHERE config_name = 'google_visit_counter'";
	if( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not update google counter information', '', __LINE__, __FILE__, $sql);
	}

	$google_visit_counter++;
}
// ------------------------------------
Wenn ich das richtig verstehen, orientiert der sich nur an einer IP-Adresse. Ist es möglich den so umzustricken, das der sich an den Spider-Footprints orientiert?
Google hinterlässt ja bspw. auch "Mediapartners-Google/2.1" oder " Gecko/20060111 Googlebot 2.1" in meiner accesslog-Datei. KAnn man darauf nicht aufsetzen?
Bild
blackgoofy
Beiträge: 13
Registriert: So 05.Mär, 2006 18:34

Beitrag von blackgoofy »

also ich habe den mod drin... (http://www.phpbbmods.de/ftopic43.html) damit lassen sich die boteinstellungen im acp verwalten.... habe dann noch mein portal etwas erweiter bzw die anzeige dort eingebaut und habe nun einen schonen counter wie ich finde...
Benutzeravatar
karstenkurt
Beiträge: 597
Registriert: Do 31.Mär, 2005 20:20
Kontaktdaten:

Beitrag von karstenkurt »

Danke, den schau ich mir mal an.
Bild
Benutzeravatar
AmigaLink
Beiträge: 5843
Registriert: Mi 03.Mär, 2004 09:05
Wohnort: NRW
Kontaktdaten:

Beitrag von AmigaLink »

[center].: Web Relax .::. Essen mit Freude .::. AmigaLink.de :.
______________________________________

Kein Support per PM, ICQ oder eMail!!!
[/center]
Benutzeravatar
karstenkurt
Beiträge: 597
Registriert: Do 31.Mär, 2005 20:20
Kontaktdaten:

Beitrag von karstenkurt »

Wie kann ich denn dem vom BlackGoofy empfohlenen Mod, die vom Bot gespiderten Seiten abringen?
Edit: Wäre das ein gangbarer Weg?
Neue Tabelle

Code: Alles auswählen

CREATE TABLE `phpbb_bots_log` (
`BotID` SMALLINT( 2 ) NOT NULL ,
`BotURL` VARCHAR( 255 ) NOT NULL ,
`visitdate` VARCHAR( 255 ) NOT NULL 
) TYPE = MYISAM ;
In Constants.php neue Konstante definieren

Code: Alles auswählen

define('BOT_LOG_TABLE', $table_prefix.'bots_log');
Funktion is_robot in function.php erweitern

Code: Alles auswählen

function is_robot()
{
  global $db, $HTTP_SERVER_VARS, $table_prefix;
  // define bots table - for the users who are to lazy to edit constants.php hehehe!
  define('BOTS_TABLE', $table_prefix . "bots");

  // get required user data
  $user_ip = $HTTP_SERVER_VARS['REMOTE_ADDR'];
  $user_agent = $HTTP_SERVER_VARS['HTTP_USER_AGENT'];
  
  //NEU  
  $requested_url=$HTTP_SERVER_VARS['REQUEST_URI'];

  // get bot table data
  $sql = "SELECT bot_agent, bot_ip, bot_id, bot_visits, last_visit, bot_pages, bot_name
  FROM " . BOTS_TABLE;

  if ( !($result = $db->sql_query($sql)) )
  {
      message_die(GENERAL_ERROR, 'Could not obtain bot data.', '', __LINE__, __FILE__, $sql);
  }

  // loop through bots table
  while ($row = $db->sql_fetchrow($result))
  {
    // clear vars
    $agent_match = 0;
    $ip_match = 0;

		// check for user agent match
		foreach (explode('|', $row['bot_agent']) as $bot_agent)
		{
			if ($row['bot_agent'] && $bot_agent != '' && preg_match('#' . preg_quote($bot_agent, '#') . '#i', $user_agent)) $agent_match = 1;
		}

		// check for ip match
		foreach (explode('|', $row['bot_ip']) as $bot_ip)
		{
			if ($row['bot_ip'] && $bot_ip != '' && strpos($user_ip, $bot_ip) === 0)
			{
				$ip_match = 1;
				break;
			}
		}
		// if both ip and agent matched update table and return true
		if ($agent_match == 1 && $ip_match == 1)
		{
			
			// get time - seconds from epoch
			$today = time();

			$last_visits = explode('|', $row['last_visit']);
			
			// if half an hour has passed since last visit
			if (($today - (($last_visits[0] == '') ? 0 : $last_visits[0])) > 2700)
			{
				
				for ($i = ((4 > sizeof($last_visits)) ? sizeof($last_visits) : 4); $i >= 0; $i--)
				{
					if ($last_visits[$i-1] != '') $last_visits[$i] = $last_visits[$i-1];
				}

				// increment the new visit counter
				$row['bot_visits']++;

				// clear prior indexed pages
				$row['bot_pages'] = 1;
			} else {
				// add to indexed pages
				$row['bot_pages']++;
			}

			$last_visits[0] = $today;

			// compress it all together
			$last_visit = implode("|", $last_visits);

			// update table
			$sql = "UPDATE " . BOTS_TABLE . "
			SET last_visit='$last_visit', bot_visits='" . $row['bot_visits'] . "', bot_pages='" . $row['bot_pages'] . "'
			WHERE bot_id = " . $row['bot_id'];
			if ( !($result2 = $db->sql_query($sql)) )
			{
				message_die(GENERAL_ERROR, 'Couldn\'t update data in bots table.', '', __LINE__, __FILE__, $sql);
		}

//NEU
      $sql = "INSERT INTO " . BOT_LOG_TABLE . " (BotID, BotURL, visitdate)
			VALUES (" . $row['bot_id'] .",'" . $requested_url . "'," . $today . ")";
			if ( !$db->sql_query($sql) )
			{
				message_die(GENERAL_ERROR, 'Could not insert bot URL', '', __LINE__, __FILE__, $sql);
			}
//***
			return $row['bot_name'];

		}
		else
		{
			if ($agent_match == 1 || $ip_match == 1)

			{

				// get data from table
				$sql = "SELECT pending_" . ((!$agent_match) ? 'agent' : 'ip') . "
				FROM " . BOTS_TABLE . "
				WHERE bot_id = " . $row['bot_id'];

				if ( !($result2 = $db->sql_query($sql)) )
				{
					message_die(GENERAL_ERROR, 'Could not obtain bot data.', '', __LINE__, __FILE__, $sql);
				}

				$row2 = $db->sql_fetchrow($result2);

				// add ip/agent to the list
				$pending_array = (( $row2['pending_' . ((!$agent_match) ? 'agent' : 'ip')] ) ? explode('|', $row2['pending_' . ((!$agent_match) ? 'agent' :  'ip')]) : array());

				$found = 0;

				if ( sizeof($pending_array) )
				{
					for ($loop = 0; $loop < count($pending_array); $loop+=2)
					{
						if ($pending_array[$loop] == ((!$agent_match) ? $user_agent : $user_ip)) $found = 1;
					}
				}

				if ($found == 0)
				{
					$pending_array[] = ((!$agent_match) ? str_replace("|", "|", $user_agent) : $user_ip);
					$pending_array[] = ((!$agent_match) ? $user_ip : str_replace("|", "|", $user_agent));
				}
				$pending = implode("|", $pending_array);

				// update table
				$sql = "UPDATE " . BOTS_TABLE . "
				SET pending_" . ((!$agent_match) ? 'agent' : 'ip') . "='$pending'
				WHERE bot_id = " . $row['bot_id'];

				if ( !($result2 = $db->sql_query($sql)) )
				{
					message_die(GENERAL_ERROR, 'Couldn\'t update data in bots table.', '', __LINE__, __FILE__, $sql);
				}
//NEU				
$sql = "INSERT INTO " . BOT_LOG_TABLE . " (BotID, BotURL, visitdate)
				VALUES (" . $row['bot_id'] .",'" . $requested_url . "'," . $today . ")";
				if ( !$db->sql_query($sql) )
				{
					message_die(GENERAL_ERROR, 'Could not insert bot URL', '', __LINE__, __FILE__, $sql);
//****
				}
			}
		}

	}

	return 0;
}
Zuletzt geändert von karstenkurt am So 23.Apr, 2006 18:17, insgesamt 1-mal geändert.
Bild
blackgoofy
Beiträge: 13
Registriert: So 05.Mär, 2006 18:34

Beitrag von blackgoofy »

was meinst du damit ?
Benutzeravatar
karstenkurt
Beiträge: 597
Registriert: Do 31.Mär, 2005 20:20
Kontaktdaten:

Beitrag von karstenkurt »

Habs schon gemacht. siehe oben.
Bild
blackgoofy
Beiträge: 13
Registriert: So 05.Mär, 2006 18:34

Beitrag von blackgoofy »

ja dann.. und der ist doch besser, oder :)

würde den teil mit > 2700 in der function etwas anpassen... ist etwas viel meiner meinung nach... ich habe es zur zeit auf > 600 ...
Benutzeravatar
karstenkurt
Beiträge: 597
Registriert: Do 31.Mär, 2005 20:20
Kontaktdaten:

Beitrag von karstenkurt »

Danke für den Tipp. Ja besser schon ,aber es fehlen halt noch enige Sacen. Aber die kann ich mir ja nachbauen :)

Edit: Das Teil funktioniert:)) Hab gerade den Googlebot gefangen, welcher 5 Seiten gespiedert hat. Steht im Log genau welche:))) Warum der eine Seite aber zweimal aufruft?
Zuletzt geändert von karstenkurt am So 23.Apr, 2006 20:15, insgesamt 1-mal geändert.
Bild
Antworten