php log function

php
Here is the log function that i use in my application(s):


<?php

/*

$handle = fopen(“file.txt”, “r”);

$handle = fopen(“file.gif”, “wb”);

$handle = fopen(“http://www.google.com/&#8221;, “r”);

$handle = fopen(“ftp://user:password@example.com/somefile.txt”, “w”);*/

$ip = $_SERVER[‘REMOTE_ADDR’];

$date = date(“Y-m-d h:ia”);

$txtlog = “log.txt”;

//$page = “”;//$_SERVER[PHP_SELF];

//$page .= $_SERVER[‘HTTP_REFERER’];

$page = $_SERVER[‘REQUEST_URI’];

if(is_writable($txtlog)) {

$fp = fopen($txtlog, “a+”);// or die(“Error occured while opening file.”);

//$filedata = fread($fp, filesize($txtlog));

$mystr = “$ip|$date|$page\n”;

//rewind($fp);

fwrite($fp, $mystr);

fclose($fp);

} else {

$fp = fopen(“log.txt”,“a+”);

fclose($fp);

}

?>

— by apit

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s