note 110874 added to function.file-put-contents
| From: | YousefIsmaeil-Cliprz | Date: | Tue, 18 Dec 2012 00:25:54 +0000 |
| Subject: | note 110874 added to function.file-put-contents | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-192573@lists.php.net to get a copy of this message | ||
<?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].
?>
----
Server IP: 69.147.83.199
Probable Submitter: 78.89.32.114
----
Manual Page -- http://php.net/manual/en/function.file-put-contents.php
Edit -- https://master.php.net/note/edit/110874
Del: integrated -- https://master.php.net/note/delete/110874/integrated
Del: useless -- https://master.php.net/note/delete/110874/useless
Del: bad code -- https://master.php.net/note/delete/110874/bad+code
Del: spam -- https://master.php.net/note/delete/110874/spam
Del: non-english -- https://master.php.net/note/delete/110874/non-english
Del: in docs -- https://master.php.net/note/delete/110874/in+docs
Del: other reasons-- https://master.php.net/note/delete/110874
Reject -- https://master.php.net/note/reject/110874
Search -- https://master.php.net/manage/user-notes.php