<?php
///////////////////////////////////////////////////////////////////////////////////////////////////////
// BotBanish 9.0.05
// Randem Systems: https://randemsystems.support
// BotBanish Session Routines
// Date: 09/29/2026
//
///////////////////////////////////////////////////////////////////////////////////////////////////////

function BotBanishSessionGetPrefix($no_ip = false, $lock_ip = '') {

	require_once BOTBANISH_DIR . 'Subs/BotBanish_Subs.php';

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

	$ip = ($no_ip === true) ? '' : BotBanishGetIP() . '_' . $system . '_';
	$ip = !empty($lock_ip) ? $lock_ip . '_' . $system . '_' : $ip;
	$prefix = $ip . BOTBANISH_SESSION . '_';
	return $prefix;
}

function BotBanishRetrieveSessionInfo($ip) {

	$BotBanishCache = BotBanishGetCache();
	$BotBanishSession = BotBanishGetSession();

	$date = BotBanishGetCorrectDateTimeB();

	$first_hit = $BotBanishSession->getSessionKey('firsthit');
	$BotBanishSession->setSessionKey('firsthit', empty($first_hit) ? $date : $first_hit);

	$last_hit = $BotBanishSession->getSessionKey('lasthit');
	$BotBanishSession->setSessionKey('lasthit', empty($last_hit) ? $date : $last_hit);

	$hit_count = intval($BotBanishSession->getSessionKey('hitcount'));
	$hit_count = empty($hit_count) ? 1 : $hit_count;
	$BotBanishSession->setSessionKey('hitcount', empty($hit_count) ? 1 : $hit_count);

	$BotBanishCache->setCacheObject($ip, $BotBanishSession);

	return array('first_hit' => $first_hit, 'last_hit' => $last_hit, 'hit_count' => $hit_count);
}

function BotBanishUpdateSessionInfo($ip, $sessionInfo) {

	$BotBanishCache = BotBanishGetCache();
	$BotBanishSession = BotBanishGetSession();
	
	$BotBanishSession->setSessionKey('firsthit', $sessionInfo['first_hit']);
	$BotBanishSession->setSessionKey('lasthit', $sessionInfo['last_hit']);
	$BotBanishSession->setSessionKey('hitcount', $sessionInfo['hit_count']);

	$BotBanishCache->setCacheObject($ip, $BotBanishSession);
}
?>