some one look at this and tell me why it dont work

by Terry Goode <tgoode(at)earthlink.net>

 Date:  Thu, 19 Aug 2004 08:04:02 -0400
 To:  HWG Techniques <hwg-techniques(at)mail.hwg.org>
  todo: View Thread, Original
my server runs php4 if it will help, i didnot write it so am lost
--------------
<?php
/* PHP3 Mail-Log */

/* *********************** */
/* Configuration Variables */
/* *********************** */

/* Your E-Mail Address */
$mailconfto = "terry(at)terry-g.net";

/* The From Address you want shown on the e-mail */
$mailconffrom = "weblogs(at)terry-g.net";

/* The Subject you want shown on the e-mail */
$mailconfsubject = "terry-g.net logs";

/* Your Server name (without the www.) */
$mailconfserver = "terry-g.net";

/* Minimum number of entries before the logs are e-mailed */
$mailconfmin = 1;

/* Path to the log file. The file *MUST* be writable by the script */
$logfile = "http://www.terry-g.net/maillogs/logsfile.txt";

/* ************************************** */
/* DO NOT CHANGE ANYTHING PAST THIS POINT */
/* ************************************** */
$results = array();

/* Only run on our server... */
$mailconfserver1 = "www." . $mailconfserver;
if (($HTTP_HOST == $mailconfserver) or ($HTTP_HOST == $mailconfserver1))
{

    /* Get a the current date and time, formated */
    $shortdate = date("Y-m-d H:i");

    /* Attempt to resolve remote host name */
    $host_name = gethostbyaddr($REMOTE_ADDR);

    /* Build log string for writing */
    $log_rec = "Time: " . $shortdate . "\n";
    $log_rec .= "Referer: " . $_server['HTTP_REFERER'] . "\n";
    $log_rec .= "IP: " . $_server['REMOTE_ADDR'] . ", Host: " . 
$host_name . "\n";
    $log_rec .= "With: " . $_server['HTTP_USER_AGENT'] . "\n";
    $log_rec .= "Page: " . $_server['REQUEST_URI'] . "\n\n";

    /* Open log file and write details                  */
    /* NOTE: If we can't open the log file, it is more  */
    /* important to get on with displaying the page     */
    /* than worrying about a few lost logs! So there is */
    /* -deliberately- no failure processing here.       */

    $fp = @fopen($logfile, "a");

    if ($fp)
    {
        fwrite($fp, $log_rec);
        fclose($fp);

        /* Now open the log file and count the number of entries */
        unset ($results);
        $results = file($logfile);
        if (count($results) > 1)
        {
            /* Each log entry has 6 lines, so adjust for this */
            $log_entries = (count($results) / 6);

            /* If more than the defined number of logs, send e-mail and 
zap file */
            if ($log_entries >= $mailconfmin)
            {
                /* Convert the array to a string for sending mail */
                reset ($results);
                $message = "\n\n";
                while (list(, $resultl) = each ($results))
                {
                    $message .= $resultl;
                }

                /* Now send the mail */
                if (mail($mailconfto, $mailconfsubject, $message, "From: 
$mailconffrom"))
                {
                    /* Mail sent so zap the file */
                    $fp = @fopen($logfile, "w");
                    if ($fp)
                    {
                        fclose($fp);
                    }
                }
            }
        }
    }
}
?>

-- 
Terry G.
mailto:tgoode(at)earthlink.net

HWG hwg-techniques mailing list archives, maintained by Webmasters @ IWA