PHP: User Logging

pulse__xx

Member
Messages
350
Reaction score
0
Points
16
Description
A user log can be useful in keeping track of your visitors and where they are from. The user log in this tutorial will record your users time/date of their visit, their IP, their referrer, their browser information, and the page they viewed. To see my user log in action, click here. (IP logging is blocked for privacy).

Implementation
First, you will need to create a log.html file and copy and paste the following code:



QUOTE
<table width="100%" border="1" cellspacing="1" cellpadding="1" >
<tr bgcolor="#FFFF00">
<th>Time/Date</th>
<th>IP</th>
<th>Referrer</th>
<th>Browser</th>
<th>Page</th>
</tr>

Next, copy and paste the following code to the page(s) on your site where you would like to log your users' information (most likely your main/index page):



QUOTE
<?php

// Get user's time/date
$time = date("F jS Y, h:iA");

// Get user's IP address
$ip = $REMOTE_ADDR;

// Get user's referrer
$referer = $HTTP_REFERER;

// Get user's browser
$browser = $HTTP_USER_AGENT;

// Get page user came from
$page = $_SERVER['REQUEST_URI'];

$fp = fopen("log.html", "a");

// Print user information to log.html file
fputs($fp, "
<tr>
<td>$time</td>
<td>$ip</td>
<td><a href=$referer>$referer</a></td>
<td>$browser</td>
<td><a href=$page>$page</a></td></tr>
");

fclose($fp);
?>

Where it says log.html, leave it the way it is if your log.html file is in the same directory as the page(s) you've pasted this code to. Otherwise, replace it with the correct relative URL to your log.html file.

Upload all your files and ChMOD your log.html file to 777.

Sysque Studios for more Tutorials.

This tutorial is brought to you by http://so-you.net/
 
Last edited:

XUnreal

New Member
Messages
370
Reaction score
0
Points
0
NedreN, please stop having a go at pulse_xx, hes not saying its his but he does need to put a copyright on it.
 

Jake

Developer
Contributors
Messages
4,057
Reaction score
5
Points
0
XUnreal, do you get what he is doing? no?

well hes posting for points, simple as that, using other peoples work to gain points quickly
 
Top