|
Posted by Steve on 11/10/06 00:23
"moosus" <junk{@}fishingmonthly.com.au> wrote in message
news:C179F8CC.91EE%junk{@}fishingmonthly.com.au...
| Steve
|
| Thanks for the reply.
|
| I am not against doing it using a DB as I have access to one.
|
| I am assuming that I would have to track users by using a session?
|
| Really what I need to be able to do is track the number of visitors I have
| to specific pages (ie venue.php?vid=10)
|
| If you can give me any pointers I would appreciate it
|
| Cheers
| moosus
you can create a required file and require_once to have it in any page you
want tracked. this would be the code in that file (call it
'site.tracking.php', for the sake of argument here):
<?
function siteTracking($page, $user = '')
{
$ip = '';
if (!$ip = $_SERVER['HTTP_CLIENT_IP'])
{
if (!$ip = $_SERVER['HTTP_X_FORWARDED_FOR'])
{
if (!$ip = $_SERVER['REMOTE_ADDR']){ $ip = 'UNKNOWN'; }
}
}
$sql = "
INSERT INTO siteTracking
(
Page ,
IpAddress ,
UserName ,
Stamp
)
VALUES
(
'" . $page . "' ,
'" . $ip . "' ,
'" . $user . "' ,
'" . date('Y-m-d H:i:s') . "'
)
";
db::execute($sql); // php 5. my abstract db class.
// substitute this with your
// system's requirements.
}
?>
so here's a page that would use the function to track a visit:
<?
require_once 'site.tracking.php';
siteTracking($_SERVER['PHP_SELF'], $userName);
?>
the $userName variable is ficticious but represents the login name of a user
who may be logged in. if you'd like a sample report class to display any
query's results, i'm happy to give you a sample that would do nicely with
the tracking piece above.
hth,
me
[Back to original message]
|