<?php
///////////////////////////////////////////////////////////////////////////////////////////////////////
// BotBanish 9.0.05
// Randem Systems: https://randemsystems.support
// BotBanish Session Object Class
// Date: 07/29/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,
			'webserver' => '',
			'serverurl' => '',
			'scripturl' => $this->getSessionURL(),
			'locked' => false,
			'updated' => false,
			'expires' => $date + $BotBanishSettings['BOTBANISH_SESSION_TIMEOUT'],
			'countryinfo' => $geoInfo['country_info'],
			'geodata' => $geoInfo['geo_data'],
		);
    }

	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 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();
	}
}
?>