I have written the following log script:
<?php
// Script Name: SDH Visitor WebLog 3.0
// Script Version: 3.0
// Author: Sven David Hildebrandt
// Email: webmaster@eternityweb.net
// Web site: http://home.hia.no/~sdhild99/
// http://hildebrandt.no
$time = 2592000; // 1 month
if (!$HTTP_COOKIE_VARS["count"])
{
$visitor_time = date("F jS Y, h:iA");
if (gethostbyaddr($REMOTE_ADDR) == "") $visitor_hostname = "Could not resolve hostname";
$visitor_hostname = gethostbyaddr($REMOTE_ADDR);
if ($REMOTE_ADDR == "") $visitor_IP = "There is No address";
else $visitor_IP = $REMOTE_ADDR;
if ($HTTP_REFERER == "") $visitor_referer = "No referer";
else $visitor_referer = $HTTP_REFERER;
if ($HTTP_USER_AGENT == "") $visitor_useragent = "No browser or other browser used";
else $visitor_useragent = $HTTP_USER_AGENT;
if ($HTTP_ACCEPT_LANGUAGE == "") $visitor_browserlanguage = "Could not detect language";
else $visitor_browserlanguage = getenv("HTTP_ACCEPT_LANGUAGE");
if ($REMOTE_PORT == "") $visitor_remoteport = "Could not detect remote port";
else $visitor_remoteport = getenv("REMOTE_PORT");
$fp = fopen("/home/eternity/www/visitors.php", "a"); // Make sure you edit this
fputs($fp, "<br /><b>New Visitor:</b> $visitor_time
<br>
<table width=\"100%\">
<tr bgcolor=\"#B0C4DE\"><td><b>Hostname: </b> $visitor_hostname</td></tr>
<tr bgcolor=\"#D3D3D3\"><td><b>IP: </b> $visitor_IP</td></tr>
<tr bgcolor=\"#B0C4DE\"><td><b>Referer: </b> $visitor_referer</td></tr>
<tr bgcolor=\"#D3D3D3\"><td><b>Browser & OS: </b> $visitor_useragent</td></tr>
<tr bgcolor=\"#B0C4DE\"><td><b>Browser Language: </b> $visitor_browserlanguage</td></tr>
<tr bgcolor=\"#D3D3D3\"><td><b>Remote Port: </b> $visitor_remoteport</td></tr>
</table>
");
fclose($fp);
}
?>
<script language="Javascript" type="text/javascript">
function browserFunction()
{
var screenw = window.screen.width;
var screenh = window.screen.height;
var colordepth = window.screen.colorDepth;
if (navigator.javaEnabled()) {
var java_e = "Yes";
} else {
var java_e = "No";
}
var url = "window.php?&resolution=" + screenw + " x " + screenh + " and ColorDepth: " + colordepth + " bit " + "<br /> Java Enabled: " + java_e + "<br />";
window.open(url, "Log", "width=1,height=1,top=0,left=0");
}
</script>
</HEAD>
<BODY onLoad="browserFunction()">
All of the above goes into the index.php file
<?
// Script Name: Log Visitors
// Script Version: 3.0
// Author: Sven David Hildebrandt
// Email: webmaster@eternityweb.net
// Web site: http://home.hia.no/~sdhild99/
$tid = 2592000; // 1 month
setcookie("log","write",time()+$tid);
if (!$HTTP_COOKIE_VARS["php"])
{
$fp = fopen("/home/eternity/www/visitors.php", "a"); // Make sure you edit this
fputs($fp, "
<table width=\"100%\">
<tr bgcolor=\"#B0C4DE\"><td><b>Resolution and Java: </b> $resolution</td></tr>
</tr></table>
");
fclose($fp);
}
?>
<head>
<script language="javascript" type="text/javascript">
function closeWindow()
{
window.close();
}
</script>
</head>
<body onLoad="closeWindow()">
</body>
The above text (up to the dotted line) goes into a file called window.php
This script is a combined PHP/Javascript log script, and logs a lot of info about a visitor.
The only problem with it, is that sometimes it writes the javascript part of the script (the visitor's screen resolution) up to 3 times in a row, though it's only supposed to write it ONE time.
For an examlple, take a look at entry # 61 (search for: New Visitor: February 18th 2002, 07:21AM ) at http://eternityweb.net/scripts/visitor.php
Is there a way to ensure that what is written by fputs() is only being written ONCE?
http://eternityweb.net/scripts/