I used a piece of code to generate a .csv file for every user and that contains the url, date/timestamp and the name.
I included the following code(file) in the header of the site with
if ( is_user_logged_in() ) {
//do include code
}
made a folder called ‘logs’ in the root of the site and protected that.
<?php
global $current_user;
get_currentuserinfo();
$firstname = $current_user->user_firstname;
$lastname = $current_user->user_lastname;
$useremail = $current_user->user_email;
$id = $current_user->ID;
$permalink = $_SERVER['REQUEST_URI'];
$date = date('Y-m-d H:i:s');
function getDomainFromEmail($email)
{
// Get the data after the @ sign
$domain = substr(strrchr($email, "@"), 1);
return $domain;
}
// Example
$domain = getDomainFromEmail($useremail);
$data = "" . $id . ";" . $firstname . " " . $lastname . ";" . $permalink . ";" . $date . "\n";
$file_name = "logs/".$firstname."-".$lastname."-".$id."-@".$domain.".csv";
$max_lines = 250; #maximum number of lines you want the file to have
$new_line = $data; #content of the new line to add to the file
$file_lines = file($file_name); #read the file's lines into an array
#remove elements (lines) from the end of the
#array until there's one less than $max_lines
while(count($file_lines) >= $max_lines) {
#remove the last line from the array
array_pop($file_lines);
}
#add the new line to the front of the array
array_unshift($file_lines, $new_line);
#write the lines to the file
$fp = fopen($file_name, 'w'); #'w' to overwrite the file
fwrite($fp, implode('', $file_lines));
fclose($fp);
?>
It isn’t the most efficient way and I dont know how the web server is going to act when u have a lot of logged in users at the same time, but it works for me