<?php
///////////////////////////////////////////////////////////////////////////////////////////////////////
// BotBanish 9.0.05
// Randem Systems: https://randemsystems.support
// BotBanish Website Page Logging Script
// Date: 07/29/2026
//
// Server Usage: https://botbanish.com/BotBanish/bot_v4.x.xx/Analytics/BotBanishAnalyticsLog.php?pagename=YOURPAGENAME&user_id=xxxxx
//
// Local Usage: http://YOURDOMAIN.com/BotBanish/bot_v4.x.xx/Analytics/BotBanishAnalyticsLog.php?pagename=YOURPAGENAME
//
// Function: Log website visitors
// NOTE: The user_id parameter is only used if analytics is stored on the server.
///////////////////////////////////////////////////////////////////////////////////////////////////////

	$method = isset($_GET['pagename']) ? $_GET : '';
	$method = (empty($method) && isset($_POST['pagename'])) ? $_POST : $method;
	
	if (empty($method))
		return;
	
	$pagename = isset($method['pagename']) ? $method['pagename'] : '';
	$userid = isset($method['user_id']) ? intval($method['user_id']) : 0;
	$location = isset($_GET['loc']) ? $_GET['loc'] : '';
	$system = isset($_GET['system']) ? $_GET['system'] : '';

	// If there is no page name, we can do nothing here!

	if (empty($pagename))
		return;

	if (!defined('BOTBANISH_CLIENT_DEBUG'))	
		define('BOTBANISH_CLIENT_DEBUG', false);

	if (!function_exists('BotBanishSetSettings')) {

		$filename = $location . '/bot/Include/BotBanish_PreInclude.php';
		
		if (!file_exists($filename)) {
			
			$self = substr($_SERVER['PHP_SELF'], strripos($_SERVER['PHP_SELF'], '/') + 1);
			$filename = realpath(str_ireplace($self, '../Include/BotBanish_PreIncludes.php', $_SERVER['SCRIPT_FILENAME']));
		}
		
		require_once $filename;
	}

	if (isset($BotBanishSettings['BOTBANISH_SERVERSIDE_ANALYTICS']) && $BotBanishSettings['BOTBANISH_SERVERSIDE_ANALYTICS'])
		header('location: ' . $_SERVER["REQUEST_SCHEME"] . '://' . $_SERVER["SERVER_NAME"] . '/BotBanish/bot/Analytics/BotBanishAnalytics.php?pagename=' . $pagename);

	if (!isset($BotBanishSettings['BOTBANISH_ANALYTICS_WEBSITE']) || !$BotBanishSettings['BOTBANISH_ANALYTICS_WEBSITE'])
		return;
	
	// No record keeping on installed IP

	$ip = BotBanishGetIP();
//	BotBanishCountHits($ip);
	
	if (BotBanishCheckForGoodIP($ip)) return; // If we should not check IP, do nothing
	if (BotBanishCheckForBadIP($ip)) BotBanishRedirectExit($BotBanishSettings['BOTBANISH_IP_LOCKOUT'], $ip);

//	BotBanishCountPageHits($ip);

	// Make sure user is allowed to access system
	// only do this if the page name is not a contact page otherwise record the access
	// We do this for if BotBanish is blocking a user, the user can contact the webmaster

	$botbanish_system = BotBanishCheckSystem();
	$system = $botbanish_system['system'];

	if (!isset($BotBanishSettings['BOTBANISH_TIMEZONE'])) BotBanishDefineGlobals('BOTBANISH_TIMEZONE', BotBanish_getWpTimezone());
	
	define('BOTBANISH_ANALYTICS', 1);

	// Log the page the user is viewing
	BotBanishLogWebsitePage($ip, $pagename, $userid, $system);
/*
function BotBanishCountPageHits($ip) {

	global $BotBanishSettings;

	// Keep track of page hits for this ip
	
	$session = BotBanishRetrieveSessionInfo($ip);
	
	$session['hit_count']++;
	$session['last_hit'] = BotBanishGetCorrectDateTimeB();

	if ($session['hit_count'] >= $BotBanishSettings['BOTBANISH_MAX_HIT_COUNT']) {

		$date = BotBanishGetCorrectDateTimeB();

		// if too many hits in less than 30 seconds, Deny this ip

		if (($date - $session['first_hit']) == $BotBanishSettings['BOTBANISH_MAX_HIT_SECONDS'])
			
			BotBanishLockOut($BotBanishSettings['BOTBANISH_HITCOUNT_LOCKOUT'], $ip);
		else
			$session['hit_count'] = 1;
		
		$session['last_hit'] = $date;
	}
	
	BotBanishUpdateSessionInfo($ip, $session);
}
*/
function BotBanishCheckForBadPagename($pagename) {

	$found = false;
	$len = strlen($pagename);
	$pos = strrpos($pagename, '.');

	// If the dot is 3 or 4 characters from the end, ignore the file name

	if ($pos !== false) {

		if ($pos >= ($len - 4))
			$found = true;
	}

	return $found;
}
?>