Creating a Simple User Log (Sample Code)

wwwglobe.jpg

//use the date() function <----- comment
$time = date("F jS Y, h:iA");

//use PHP variable $remote_addr to get ip address
$ip = $REMOTE_ADDR;

//use PHP variable $http_referer to get referer
$referer = $HTTP_REFERER;

//user PHP variable $http_user_agent to get browser
$browser = $HTTP_USER_AGENT;

//what page they came from
$page = $_SERVER['REQUEST_URI'];

//use the fopen() function
$fp = fopen("log.html", "a");

//use the fputs() function
fputs($fp, "
Time: $time
IP: $ip
Referer: $referer
Browser: $browser
Page: $page
");

fclose($fp);

?>

Note: Don’t forget to create a blank log.html page, upload it to the server in the same directory as the page where the code will be placed, and CHMOD it to 777. Also, you can put this code anywhere on your main page.

Comments are closed.