<?
###################################################################################
# TXcounter v4.0 #
# Written and Developed by: Aaron Bishell #
# Homepage: http://binary.gamer.net.nz #
# Copyright (C) 2002 Aaron Bishell - Please see readme.txt for more information #
###################################################################################
if(file_exists("cc_install.dat"))
{
if(isset($CookieValue))
{
$unique=0;
}
else
{
$unique=1;
$value="arbatrary value";
setcookie("CookieValue", "$value",time()+172800); //Set for 48 hours
}
//Gets the relative path to the CC directory
$fp=fopen("cc_install.dat","r");
$relativePath=fread($fp,filesize("cc_install.dat"));
fclose($fp);
//Opens the simplehits.dat file
$fileNameWithPathSimple=$relativePath."simplehits.dat";
$fp=fopen($fileNameWithPathSimple,"r");
$simpleHitsContents=fread($fp,filesize($fileNameWithPathSimple));
fclose($fp);
//Opens the hits.dat file
$fileNameWithPathFull=$relativePath."hits.dat";
$fp=fopen($fileNameWithPathFull,"r");
$hitsContents=fread($fp,filesize($fileNameWithPathFull));
fclose($fp);
//Gets the time from the server
$minute=(strftime("%M"));
$hour=(strftime("%H"));
//Gets date information from the server
$date=getdate();
$yday=$date['yday'];
$mday=$date['mday'];
$mon=$date['mon'];
$year=$date['year'];
//Determines the users browser
if(ereg( 'MSIE ([0-9].[0-9]{1,2})',$HTTP_USER_AGENT,$log_version))
{
$browserVersion=$log_version[1];
$broswerAgent='Internet Explorer';
}
elseif(ereg( 'Opera ([0-9].[0-9]{1,2})',$HTTP_USER_AGENT,$log_version))
{
$browserVersion=$log_version[1];
$broswerAgent='Opera';
}
elseif(ereg('Mozilla/([0-9].[0-9]{1,2})',$HTTP_USER_AGENT,$log_version))
{
$browserVersion=$log_version[1];
$broswerAgent='Mozilla';
}
else
{
$browserVersion='Unknown';
$broswerAgent='Other';
}
//Determines the OS the user is running
if (strstr($HTTP_USER_AGENT,'Win'))
{
$platform='Windows';
}
else if (strstr($HTTP_USER_AGENT,'Mac'))
{
$platform='Mac';
}
else if (strstr($HTTP_USER_AGENT,'Linux'))
{
$platform='Linux';
}
else if (strstr($HTTP_USER_AGENT,'Unix'))
{
$platform='Unix';
}
else
{
$platform='Other';
}
//Determines what url the counter is counting
$counterUrl=$HTTP_REFERER;
//Processes the data from simeplehits.dat into variables
$totalHits=explode("[total]",$simpleHitsContents);
$uniqueHits=explode("[unique]",$simpleHitsContents);
//Increments the two variables
if($unique==1)
{
$uniqueHits[1]=$uniqueHits[1]+1;
}
$totalHits[1]=$totalHits[1]+1;
//Write to simplehits.dat
$simpleHitsContents="[total]".$totalHits[1]."[total][unique]".$uniqueHits[1]."[unique]";
$fp=fopen($fileNameWithPathSimple,"w");
fputs($fp,$simpleHitsContents,strlen($simpleHitsContents));
fclose ($fp);
//Append to hits.dat
$fullHitsContents="[~]".$hour."|".$minute."|".$yday."|".$mday."|".$mon."|".$year."|".$unique."|".$counterUrl."|".$broswerAgent."|".$browserVersion."|".$platform."[~]\n";
$fp=fopen($fileNameWithPathFull,"aw");
fputs($fp,$fullHitsContents,strlen($fullHitsContents));
fclose ($fp);
}
if(!file_exists("cc_install.dat"))
{
//Output the information for formatting
?> <html>
<head>
<title>TXcounter v4.0</title>
<style>
BODY
{
BACKGROUND: #FFFFFF;
COLOR: #000000;
FONT-FAMILY: Verdana, Helvetica;
FONT-SIZE: 9pt
}
</style>
</head>
<body> <?
//Check to see that this page has not been called by a submitted CC url
if($txc_url=="")
{
?> You need to install this counter file.
<br><br>
Enter the full url to the Cookie Counter <b>directory</b> (<b>including</b> the http:// and <b>with</b> an ending slash):
<form method=post action=tx_counter.php>
<input type=text name=txc_url size=100>
<input type=submit value=submit>
</form> <?
}
//However if it has been called by itself with a url under the name txc_url
if($txc_url!="")
{
//Check to make sure txc_url is correct
$fileWithUrl=$txc_url."hits.dat";
@$file=fopen($fileWithUrl, "r"); //Using this since file_exists() only works for relative filepaths
if(!$file)
{
?> That url is incorrect. Press back to try again. <?
exit();
}
//Converts the txc_url to a realtive path
$slashesCCurl=substr_count($txc_url,"/");
$slashesReferer=substr_count($HTTP_REFERER,"/");
if($slashesCCurl<$slashesReferer) //If you are "higher" than the TXcounter dir
{
?> Unfortunately you cant place the tx_counter.php file here. <?
exit();
}
if($slashesCCurl>$slashesReferer) //If you are "below" the TXcounter dir
{
$amountToChopTo=(strrpos($HTTP_REFERER,"/"))+1; //Finds the last slash position
$refererWithoutFilename=substr($HTTP_REFERER, 0, $amountToChopTo); //Chops everything up to last slash
$relative_path=str_replace($refererWithoutFilename,"",$txc_url);
}
if(($slashesCCurl==$slashesReferer) && (strcmp($txc_url,$HTTP_REFERER)==0))
{
?> Unfortunately you cant place the tx_counter.php file here. <?
exit();
}
//Saves the relative path
$fp=fopen("cc_install.dat","w");
fputs($fp,$relative_path,strlen($relative_path));
fclose ($fp);
?> Url saved successfully, this counter should be functional. <?
}
}
?>
</body>
</html>