Skip to content

Instantly share code, notes, and snippets.

@mipmip
Created February 16, 2012 12:12
Show Gist options
  • Save mipmip/1844419 to your computer and use it in GitHub Desktop.
Save mipmip/1844419 to your computer and use it in GitHub Desktop.
Quick and dirty logging in PHP
<?php
function log($msg)
{
//using the date() function
$time = date("F jS Y, h:iA");
//$remote_addr is PHP variable to get ip address
$ip = $REMOTE_ADDR;
//$http_referer is PHP variable to get referer
$referer = $HTTP_REFERER;
//$http_user_agent is PHP variable for browser
$browser = $HTTP_USER_AGENT;
//what page they came from
$page = $_SERVER['REQUEST_URI'];
//use the fopen() function
$fp = fopen("/tmp/jinn.log", "a");
//using the fputs() function
fputs($fp, "
Time: $time
IP: $ip
Referer: $referer
Browser: $browser
Page: $page
Msg: $msg
");
fclose($fp);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment