<?
/*
KISGB - a Guest Book script written in PHP.
Copyright (C) 2001-2002 Gaylen Fraley
hide@address.com
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
License file for more details.
*/
/****************************************************************
KISGB DOES NOT REQUIRE THAT YOU USE THIS!!!!!!
****************************************************************/
/*
The logfile class allows you to write out a log from the index.php
file or the addtogb.php file. It can be used elsewhere, but it really
doesn't make sense to. To use it, you must include it AFTER the
language file and config files are included.
Example usage:
$objLog = new logfile();
$objLog->logvars[] = $HTTP_SERVER_VARS["REMOTE_ADDR"];
$objLog->logvars[] = $HTTP_USER_AGENT;
$objLog->logvars[] = date($date_format);
$objLog->logvars[] = date($time_format);
$objLog->logvars[] = $PHP_SELF;
$objLog->writelog();
The default logfile name is "logs/kisgb.log.php" and the deafult separator is
a vertical bar "|". You can override both of these when you instantiate the
class, as in:
$objLog = new logfile("/usr/web/docs/myguestbook.log.php","~");
This would write entries to /usr/web/docs/myguestbook.log.php file and would create it, if
it doesn't already exist. This would track visitors: ip, browser, date/time,
and url.
You control the placement of this code in the index.php and addtogb.php files.
This is really specialized code for very specific tracking purposes and to
demonstrate it, I have included a index_with_log.php that will show
where you might want to place it. To test it, after setting up KISGB, type
http://your.url/kisgb/index_with_log.php , instead of
http://your.url/kisgb/index.php . You shoud then see a kisgb.log.php file
in your kisgb directory with the tracking variables in it.
*/
class logfile
{
var $logvars
,$path_to_log
,$separator;
function logfile($log_file="logs/kisgb.log.php",$sep="|")
{
$this->path_to_log = $log_file;
$this->separator = $sep;
}
function writelog()
{
GLOBAL $unable_to_access_file_msg;
$log = @fopen($this->path_to_log,"a") or die($unable_to_access_file_msg." ".$this->path_to_log);
@flock($log,1);
foreach ($this->logvars as $strname)
{
@fwrite($log,$this->separator.$strname);
}
@fwrite($log,"\n");
@flock($log,3);
@fclose($log);
}
function printlog($table_options='',$cell_options='')
{
GLOBAL $unable_to_access_file_msg;
$log = file($this->path_to_log);
$number_of_lines = count($log);
echo "<table align=center $table_options>";
for ($i=0; $i<$number_of_lines; $i++)
{
$line = explode($this->separator,$log[$i]);
if ($i==0)
{
$count = count($line)+1;
echo "<tr><th $cell_options align=\"center\" colspan=\"".$count."\">$this->path_to_log ( $number_of_lines )</th></tr>";
echo "<tr>";
echo "<th $cell_options> </th>";
for ($j=0;$j<count($line);$j++)
{
$k = $j+1;
${$col.$j} = "col".$k;
echo "<th $cell_options>";
if ($this->logvars[$j]>"")
{
if (substr($this->logvars[$j],0,1)=="^") echo substr($this->logvars[$j],3);
else echo $this->logvars[$j];
}
else echo ${$col.$j};
echo "</th>";
}
echo "</tr><tr>";
}
$row++;
echo "<td $cell_options>$row</td>";
$col = 0;
foreach ($line as $strname)
{
if (substr($this->logvars[$col],0,3)=="^H^") //url
{
if (substr($strname,0,7)=="http://") $pre = ""; else $pre = "http://";
echo "<td $cell_options>".str_replace($this->separator," ",$this->separator)."<a href=\"$pre".$strname."\" target=_new>$strname</a></td>";
}
elseif (substr($this->logvars[$col],0,3)=="^M^") //mail
{
echo "<td $cell_options>".str_replace($this->separator," ",$this->separator)."<a href=\"mailto:".$strname."\">$strname</a></td>";
}
else echo "<td $cell_options>".str_replace($this->separator," ",$this->separator).$strname."</td>";
$col++;
}
echo "</tr>";
}
echo "</table>";
}
function showvars()
{
foreach ($this->logvars as $strname)
{
echo $strname."<br />";
}
}
function destroy()
{
unset($logfile);
}
}
?>