Forum Moderators: coopster
Recently i've just moved to a new hosting company. my perl doesn't work with php pages anymore because there are using suPHP, the virtual () is not working.
so, i searched the web, got this script and modified it. everything is working the same way as my previous perl script, it logs everything, ... even page reload.
below is the code:
[php]
<?php
// Getting the information
$ipaddress = $_SERVER['REMOTE_ADDR'];
$page = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
$referrer = $_SERVER['HTTP_REFERER'];
$datetime = date('D, M j, Y (T) \a\t h:i:s A');
$useragent = $_SERVER['HTTP_USER_AGENT'];
$remotehost = @getHostByAddr($ipaddress);
// Create log line
$logline = $ipaddress . '¦' . $referrer . '¦' . $datetime . '¦' . $useragent . '¦' . $remotehost . '¦' . $page . "\n";
// Write to log file:
$logfile = 'log.db';
if (!$handle = fopen($logfile, 'r+')) {
die("Failed to open log file");
}
file_put_contents($logfile, $logline . file_get_contents($logfile));
fclose($handle);
?>
[/php]
appreciate if someone could help, thanks.
if (-e "$hostfile")
{
open(HOST,"$hostfile");
$hostline = <HOST>;
chop($hostline) if $hostline =~ /\n$/;
close(HOST);
($old_time,$old_number,$old_page,$old_browser) = split(/\¦/,$hostline);
}# save host and time info and check if this is a page reload
open(HOST,">$hostfile");
$seconds = time;
print HOST "$seconds\¦$ENV{REMOTE_ADDR}\¦$ENV{'DOCUMENT_URI'}\¦$ENV{'HTTP_USER_AGENT'}";
close(HOST);
if ($time - $old_time < $interval && $ENV{REMOTE_ADDR} eq $old_number && $ENV{'DOCUMENT_URI'} eq $old_page && $ENV{'HTTP_USER_AGENT'} eq $old_browser)
{
don't do anything
} else {
process it
}
i'm wondering, since php has more functionality, is session going to help?
i found this session code, but not sure about the meaning...
session_start();
$pageRefreshed = false;
if (isset($_SESSION['LAST_REQUEST']) && $_SERVER['REQUEST_URI'] === $_SESSION['LAST_REQUEST']['REQUEST_URI']) {
if (isset($_SERVER['HTTP_REFERER'])) {
// check if the last request’s referrer is the same as the current
$pageRefreshed = $_SERVER['HTTP_REFERER'] === $_SESSION['LAST_REQUEST']['HTTP_REFERER'];
} else {
// check if the last request didn’t have a referrer either
$pageRefreshed = $_SERVER['HTTP_REFERER'] === null;
}
}
// set current request as “last request”
$_SERVER['LAST_REQUEST'] = array(
'REQUEST_URI' => $_SERVER['REQEUST_URI'],
'HTTP_REFERER' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null
);
appreciate your feedback :)