<?php
if (!$in_xpai)
die;
$old_error = error_reporting (E_ALL); // This will NOT report uninitialized variables
class debug
{
var $logfilename = "./xpai.log";
var $loghost = "localhost";
var $logport = 9876;
function write_debug($debugtext)
{
if ($this->logfilename != "")
$fp = fopen($this->logfilename, "a+");
else
$fp = fsockopen($this->loghost, $this->logport);
fputs($fp, date("dmy H:i:s "));
fputs($fp, $debugtext);
fputs($fp, "\n");
fclose($fp);
}
function log_text($filename, $linenr, $logtext)
{
$logline = sprintf("LOGT: %s (%03s): %s", $filename, $linenr, $logtext);
$this->write_debug($logline);
}
function log_vars($filename, $linenr, $vararr)
{
foreach($vararr as $key=>$elem)
{
$logline = sprintf("LOGV: %s (%03s): ", $filename, $linenr);
$logline .= $key." [".gettype($elem)."]=".$elem;
$this->write_debug($logline);
}
}
function log_HTTPPOSTVARS($filename, $linenr)
{
foreach($HTTP_POST_VARS as $name=>$value)
{
$logline = sprintf("LOGHP: %s (%03s): %s = %s", $filename, $linenr, $HTTP_POST_VARS[$name], $value);
$this->write_debug($logline);
}
}
function log_HTTPGETVARS($filename, $linenr)
{
foreach($HTTP_GET_VARS as $name=>$value)
{
$logline = sprintf("LOGHG: %s (%03s): %s [%s] [%s] = %s", $filename, $linenr, $name, $value);
$this->write_debug($logline);
}
}
function log_HTTPCOOKIEVARS($filename, $linenr)
{
foreach($HTTP_COOKIE_VARS as $name=>$value)
{
$logline = sprintf("LOGHC: %s (%03s): %s [%s] [%s] = %s", $filename, $linenr, $name, $value);
$this->write_debug($logline);
}
}
}
$deb = new debug;
/*
Call with
$deb->log_text(__FILE__, __LINE__, <logtext>);
$deb->log_vars(__FILE__, __LINE__, compact("<varname>", "<varname>", ...));
$deb->log_HTTPPOSTVARS(__FILE__, __LINE__)
$deb->log_HTTPGETVARS(__FILE__, __LINE__)
$deb->log_HTTPCOOKIEVARS(__FILE__, __LINE__)
*/
//error_reporting($old_error);
?>