<?php
/*
 * Counter:
 *
 * Code by Thomas Schilb / thomasschilb.online
 * License: MIT
 *
 */
	if ($Configuration){if (file_exists("counter_conf.php")){include 'counter_conf.php';}}
	//RESET:
		if (empty($COHeight)){$COHeight="43px";}
		if (empty($COWidth)){$COWidth="105px";}
		if (empty($BGColor)){$BGColor="#666666";}
		if (empty($NUMColor)){$NUMColor="#E6E6E6";}
		if (empty($NUMSize)){$NUMSize="19px";}
		if (empty($IPColor)){$IPColor="#A4A4A4";}
		if (empty($COTime)){$COTime=1*24;}
		if (empty($IPShow)){$IPShow=true;}
		if (empty($IPSize)){$IPSize="9px";}




	/* IP des benutzers */
	if (! isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
		$LIP = $_SERVER['REMOTE_ADDR'];
	}
	else {
	$LIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
	}
	//Zahl des Zählers
	if (file_exists("counter.txt")) {
		$file = @fopen("counter.txt", "r");
		if ($file) {
			$zahl = fgets($file, 10);
		}
		fclose($file);
	}
	//Wenn die Datei Leer ist
	if (empty($zahl)){$zahl = 0;}




	//Wenn der Benutzer inerhalb der Cookie Zeit schon besucht hat
	if ($_COOKIE["ip"] == $LIP) {
		//Cookie neu setzen
		if(!$COTime){$COTime = 0.5;}
		setcookie("ip", $LIP, time()+3600*$COTime);
	}
	//Wenn der Benutzer neu ist
	else{
		//Cookie Setzen
		if(!$COTime){$COTime = 0.5;}
		setcookie("ip", $LIP, time()+3600*$COTime);		
		$zahl = $zahl+1;
		if (file_exists("counter.txt")) {
			$file = @fopen("counter.txt","w");
			if ($file) {
				fputs($file, $zahl);
				fclose($file);
			}
		}	
	}
	//output
	echo "
		<div class='counter'>
			<span class='num' >$zahl</span>
			";
			if ($IPShow) {echo "<span class='ip' >Ihre Ip: $LIP</span>";}
		echo "
		</div>
		<style type='text/css'>
			.counter span{
				display:block;
			}
			.counter{
				background-color: $BGColor;
				text-align: center;
				width: $COWidth;
				height: $COHeight;
				font-family: 'Avenir Light',Arial,sans-serif;
				border-radius: 4px;
			}
			.num{
				padding: 2px;
				color: $NUMColor;
				font-weight: bold;
				font-size: $NUMSize;
			}
			.ip{
				color: $IPColor;
				font-size: $IPSize;
				padding-left: 2px;
				padding-right: 2px;
			}
		</style>
	";
?>
