note 110874 deleted from function.file-put-contents by aharvey

From: Date: Tue, 18 Dec 2012 00:30:43 +0000
Subject: note 110874 deleted from function.file-put-contents by aharvey
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-192576@lists.php.net to get a copy of this message
Note Submitter: Yousef Ismaeil - Cliprz ---- <?php /** * Insert new logs in a txt file with file_put_contents. * * @param (string) $filename - filename by default (log.txt). * @author Yousef Ismaeil - Cliprz[at]gmail[dot]com. * @website http://cliprz.org */ function logs ($filename='log.txt') { $data = array( "ip" => (isset($_SERVER["REMOTE_ADDR"])) ? $_SERVER["REMOTE_ADDR"] : getenv("ip"), "date" => date("D d M Y h:m:s a",time()), "script_name" => (isset($_SERVER["SCRIPT_NAME"])) ? $_SERVER["SCRIPT_NAME"] : "", "query" => (isset($_SERVER["QUERY_STRING"])) ? $_SERVER["QUERY_STRING"] : "", "user_agent" => (isset($_SERVER["HTTP_USER_AGENT"])) ? $_SERVER["HTTP_USER_AGENT"] : "" ); $append = "[".$data['ip'] ."] - Date : [" .$data['date'] ."] In : [" .$data['script_name'] ." - Query " .$data['query'] ."] INFORMATIONS : [" .$data['user_agent'] ."].\n"; if (!file_exists($filename)) { #$contents = file_get_contents($filename); file_put_contents($filename,$append,FILE_APPEND); } else { file_put_contents($filename,$append,FILE_APPEND); } } // Example logs(); // Result in log.txt // [25.1323.145.234] - Date : [Tue 18 Dec 2012 01:12:52 am] In : [/logs/index.php - Query test=logs] INFORMATIONS : [Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11]. ?>

« previous php.notes (#192576) next »