<?php
///////////////////////////////////////////////////////////////////////////////////////////////////////
// BotBanish 9.0.02
// Randem Systems: https://randemsystems.support
// BotBanish Session Object Class
// Date: 07/16/2026
// Usage:
//
///////////////////////////////////////////////////////////////////////////////////////////////////////

class BotBanishSession {
    // Properties

	public $sessionInfo;

    // Constructor
    public function __construct() {

		global $BotBanishSettings;
		
		$ip = $this->getSessionIP();
		$geoInfo = BotBanishClientGetGeoInfo($ip);
		$date = BotBanishGetCorrectDateTimeB();

		$this->sessionInfo = array(
			'botip' => $ip,
			'name' =>  '',
			'user' => '',
			'value' => '',
			'func' => '',
			'firsthit' => $date,
			'lasthit' => $date,
			'hitcount' => 1,
			'countryinfo' => $geoInfo['country_info'],
			'geodata' => $geoInfo['geo_data'],
			'webserver' => '',
			'serverurl' => '',
			'scripturl' => $this->getSessionURL(),
			'locked' => false,
			'updated' => false,
			'expires' => $date + $BotBanishSettings['BOTBANISH_SESSION_TIMEOUT'],
		);
		
		$jsonData = json_encode($this->sessionInfo, JSON_PRETTY_PRINT);
//        BotBanishWriteFile($BotBanishSettings['BOTBANISH_STATIC_CACHE_DIR'] . $ip . '.info', $jsonData, true);
    }

	public function getSessionIP() {
	
		$ip = !isset($_REQUEST['ip']) || empty($_REQUEST['ip']) ? BotBanishGetIP() : $_REQUEST['ip'];
		if (isset($_REQUEST['ip'])) unset($_REQUEST['ip']);
		return $ip;
	}

	public function getSessionURL() {

		global $BotBanishSettings;

		$url = isset($BotBanishSettings['BOTBANISH_INSTALL_URL']) ? $BotBanishSettings['BOTBANISH_INSTALL_URL'] :	'';

		if (empty($url)) {

			$protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http");
			$url = $protocol . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
		}

		return $url;
	}

	public function getSessionInfo() {

		return $this->sessionInfo;
	}

	public function setSessionInfo($session = object) {

		$this->sessionInfo = $arr;
	}

	public function getSessionKey($key) {

		$key = strtolower($key);

		if (isset($this->sessionInfo[$key]))
			return $this->sessionInfo[$key];

		return false;
	}

	public function setSessionKey($key, $data = '') {

		$key = strtolower($key);
		$this->sessionInfo[$key] = $data;

		// Indicate that the session information has been changed
		// This is used in the cache module to determine if the cache object should be written to disk

		$this->sessionInfo['updated'] = BotBanishGetCorrectDateTimeB();
	}
}
?>