13-10-2005, 08:58
|
|
|
חבר מתאריך: 26.10.01
הודעות: 69
|
|
עזרה קטנה במערכת לוגים ... ?
אהלן.
אני מנסה לבנות מערכת לוגים לאתר שלי שתרשום את כול האייפים שנכנסים לאתר ואת התאריכים.
קוד PHP:
<?php $filename = 'log.txt'; $IP = $_SERVER["REMOTE_ADDR"];
$log="\n $IP ".date('d')."-".date('m')."-".date('Y')."\n\n";
// Let's make sure the file exists and is writable first. if (is_writable($filename)) {
// In our example we're opening $filename in append mode. // The file pointer is at the bottom of the file hence // that's where $somecontent will go when we fwrite() it. if (!$handle = fopen($filename, 'a')) { echo "Cannot open file ($filename)"; exit; }
// Write $somecontent to our opened file. if (fwrite($handle, $log) === FALSE) { echo "Cannot write to file ($filename)"; exit; }
echo "Success, wrote (log)";
fclose($handle);
} else { echo "The file $filename is not writable"; } ?>
עכשיו הבעיה שכול פעם שמישהו עושה רפרש הוא רושם את האייפי שלו שוב ושוב ותוך רבע שעה אני אגיע ל 10 מגה עם אותו האייפי אז השאלה היא אם יש אפשרות לעשות שקודם יבדוק אם האייפי הזה כבר קיים בקובץ ורק אם הוא לא קיים יוסיף אותו (שיבדוק רק את האייפי לא את התאריך כי זה משתנה).
|