Skip to content

Instantly share code, notes, and snippets.

@mebcomputers
Created April 29, 2012 06:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mebcomputers/2534033 to your computer and use it in GitHub Desktop.
Save mebcomputers/2534033 to your computer and use it in GitHub Desktop.
php: visitor log
$filename = 'log.txt';
$timestamp = date('l d F Y H:i:s');
$u_agent = $_SERVER['HTTP_USER_AGENT'];
$ub = '';
if(preg_match('/MSIE/i',$u_agent))
{
$ub = "Internet Explorer";
}
elseif(preg_match('/Firefox/i',$u_agent))
{
$ub = "Mozilla Firefox";
}
elseif(preg_match('/Safari/i',$u_agent))
{
$ub = "Apple Safari";
}
elseif(preg_match('/Chrome/i',$u_agent))
{
$ub = "Google Chrome";
}
elseif(preg_match('/Flock/i',$u_agent))
{
$ub = "Flock";
}
elseif(preg_match('/Opera/i',$u_agent))
{
$ub = "Opera";
}
elseif(preg_match('/Netscape/i',$u_agent))
{
$ub = "Netscape";
}
$log = $timestamp . ' ' . 'IPAddress:'. ' ' . $_SERVER['REMOTE_ADDR'] . ' ' . 'Referer:'. ' ' . $_SERVER['REQUEST_URI'] . ' ' . 'Browser:'. ' ' . $ub . ' ' . 'Username:'. ' ' . $username;
$stream = fopen("log.txt","a+");
fwrite($stream,$log ."\n");
fclose($stream);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment