I have been playing around with it but the problem is slightly different than I first thought. instead of not counting the stats from a link it will only count it once. and not again untill the browser has been closed and reopend. this occurs with firefox/mozilla/netscape
and does not occur with ie/opera ???
I'm sure its the header as it did not happen until I added that code.
okay the codes.
this is the tag that sends the info
<?php
echo <<<END
var refer = escape(document.referrer)+"";
if (!refer) { refer = "Direct Request"; };
var url = escape(document.location)+"";
//var userstring = navigator.userAgent;
var resolution = screen.width + "x" + screen.height ;
var colours = screen.colorDepth + "Bit";
tophp="&refer=" + refer + "&url=" + url + "&res=" + resolution + "&colours=" + colours;
imstring="<img src='http://www.statbox.co.uk/core/engine/addstat.php?";
prop="' alt='' border='0'>";
document.write(imstring+tophp+prop);
END;
?>
the script that process everything
<?php
//includes
include("browser_array.php"); //browser information
include("os_array.php"); //os info
//information from the JS tag
$screenres = $_GET[res];
$screendepth = $_GET[colours];
$user = $_GET[user];
//sort out any missing info
if ($screenres == "") {
$screenres = "Unknown";
}
if ($screendepth == "") {
$screendepth = "Unknown";
}
//general setings and variables
$xmlfile = "../users/basicmind/statinfo.xml"; //file stats to be written to
$browserinfo = $_SERVER['HTTP_USER_AGENT'];
$browserip = $_SERVER['REMOTE_ADDR'];
$browserhost = $_SERVER['HTTP_HOST'];
$browserref = $_SERVER['HTTP_REFERER'];
$browserroot = $_SERVER['DOCUMENT_ROOT'];
$betafile = "../beta/test.txt"; //temp file during the beta period.
$image = "http://www.statbox.co.uk/core/tag/images/sb_basic.gif"; //image that will change at a latter date, used now for verification.
//fuctions
function roundtheloop($xmlfile, $area) { //find out how many times the file needs to loop using simpleXML
$open = simplexml_load_file($xmlfile);
$loopcount = 0;
$end = 1;
while ($end == 1) {
if ($area == "browser") {
$search = $open->browser->browser[$loopcount];
} else if ($area == "os") {
$search = $open->os->os[$loopcount];
} else if ($area == "screenres") {
$search = $open->screenres->screenres[$loopcount];
} else if ($area == "screendepth") {
$search = $open->screendepth->screendepth[$loopcount];
}
if ($search == "") {
$end++;
return $loopcount;
}
$loopcount++;
}
}
function searchinfo($searchinfo, $arrayinfo) { //searchs arrays for information.
$finish = 1;
while ($finish == 1) {
$search = key($arrayinfo);
if (eregi($arrayinfo[$search], $searchinfo)) {
$result = key($arrayinfo);
return $result;
$finish = 2;
} else if ($arrayinfo[$search] == "Unknown") {
$result = $arrayinfo[$search];
return $result;
$result = 2;
} else if ($arrayinfo == "") {
$result = "Unknown";
return $result;
$finish = 2;
}
next($arrayinfo);
}
}
function insertxml($xmltype, $info, $xmlfile, $endloop) { //inserts data into the xmlsheet, will make a new node if it does not already exist.
$dom = new domDocument();
$dom->Load($xmlfile);
$end = 1;
$info = str_replace("_", " ", $info);
$xmlnode = 0;
//$endloop--;
while ($end == 1) {
$xmlatname = $dom->getElementsByTagName($xmltype)->item($xmlnode)->getAttributeNode('name')->value;
if ($xmlatname == $info) { //updates an existing node
$newstat = $dom->getElementsByTagName($xmltype)->item($xmlnode)->nodeValue++;
$end++;
} else if ($xmlnode == $endloop) { //creates a new node with the value 1
$xmlnode = 0;
$newstat = 1;
$newnode = $dom->getElementsByTagName($xmltype)->item($xmlnode);
$newElement = $dom ->createElement($xmltype);
$textNode = $dom ->createTextNode($newstat);
$newnode ->appendChild($newElement)->setAttribute('name', $info);
$newElement->appendChild($textNode);
$end++;
}
$xmlnode++;
}
$dom->save($xmlfile);
}
function showimage ($image) {
header("Location: $image");
}
//end of functions
$xmltype = "hit"; //add totalhit data
$getinfo = "totalhits";
$loopcycle = "1";
insertxml($xmltype, $getinfo, $xmlfile, $loopcycle);
$xmltype = "browser"; //add browser info
$getinfo = (searchinfo($browserinfo, $browser_search));
$loopcycle = (roundtheloop($xmlfile, $xmltype));
insertxml($xmltype, $getinfo, $xmlfile, $loopcycle);
$xmltype = "os"; //add os info
$getinfo = (searchinfo($browserinfo, $os_search));
$loopcycle = (roundtheloop($xmlfile, $xmltype));
insertxml($xmltype, $getinfo, $xmlfile, $loopcycle);
$xmltype = "screenres";
$getinfo = $screenres;
$loopcycle = (roundtheloop($xmlfile, $xmltype));
insertxml($xmltype, $getinfo, $xmlfile, $loopcycle);
$xmltype = "screendepth";
$getinfo = $screendepth;
$loopcycle = (roundtheloop($xmlfile, $xmltype));
insertxml($xmltype, $getinfo, $xmlfile, $loopcycle);
$fd = fopen($betafile, "a+") or die ("nope"); //this adds some additional data for the beta test.
$fstring = "$browserinfo : $browserip : $browserref : $browserhost : $browserroot : $user \n";
$fout = fwrite($fd, $fstring);
fclose($fd);
showimage($image);
?>
you can view the collected stats at http://www.statbox.co.uk/demo.php
and a test link to the page.
http://www.statbox.co.uk/core/alink.htm
I demo page.
http://www.statbox.co.uk/core/htmltest.htm
thanks