Log in

View Full Version : Error messages when including files in a higher directory



Spinethetic
06-05-2008, 08:05 PM
I have 3 small scripts counter that records visitor data in 3 TXT files, I have no problem when navigating pages in the root directory but once I view a page in a subdirectory I get haywire error messages about not being able to load the TXT files. The three scripts I have are
logger.php - logs users IP addresses and tracks their visit path


<?php
$theuri = $_SERVER['REQUEST_URI'];
if ( ($theuri =="/n/v.htm") or ($theuri =="/n/v.htm?id=1") or ($theuri =="/n/v.htm?id=2") or ($theuri =="/n/v.htm?id=3") or ($theuri =="/n/v.htm?id=4") or ($theuri =="/n/v.htm?id=5") or ($theuri =="/n/v.htm?id=6") or ($theuri =="/n/v.htm?id=7") or ($theuri =="/n/v.htm?id=8") or ($theuri =="/n/v.htm?id=9") or ($theuri =="/n/v.htm?id=10") or ($theuri =="/n/v.htm?id=11") or ($theuri =="/n/v.htm?id=12") or ($theuri =="/n/v.htm?id=13") or ($theuri =="/n/v.htm?id=14") or ($theuri =="/n/v.htm?id=15") or ($theuri =="/n/v.htm?id=16") or ($theuri =="/n/v.htm?id=17") or ($theuri =="/n/v.htm?id=18") or ($theuri =="/n/v.htm?id=19") or ($theuri =="/n/v.htm?id=20") or ($theuri =="/n/v.htm?id=21") or ($theuri =="/n/v.htm?id=22") or ($theuri =="/n/v.htm?id=23") or ($theuri =="/n/v.htm?id=24") or ($theuri =="/n/v.htm?id=25") or ($theuri =="/n/v.htm?id=26") or ($theuri =="/n/v.htm?id=27") or ($theuri =="/n/v.htm?id=28") or ($theuri =="/n/v.htm?id=29") or ($theuri =="/n/v.htm?id=30") or ($theuri =="/n/v.htm?id=31") ) {
$logger = "../logger.txt";
} else {
$logger = "logger.txt";
}
$fh = fopen($logger, 'a') or die("can't open file");
$log_data = date("m/d/y, g:i:s").": ".$_SERVER[REMOTE_ADDR]." went to ".$_SERVER[PHP_SELF]."\n";
fwrite($fh, $log_data);
fclose($fh);
?>

usersonline.php - prints number of visitors online


<?php
$dataFile = "usersonline.txt";

$sessionTime = 30; //this is the time in **minutes** to consider someone online before removing them from our file

//Rest of code irrelevant

?>

hitcounter.php - records number of pageviews


<?php
$theuri = $_SERVER['REQUEST_URI'];
if ( ($theuri =="/n/v.htm") ) {
$hitcounter = "../hitcounter.txt";
} else {
$hitcounter = "hitcounter.txt";
}

if (file_exists($hitcounter))
{
$fil = fopen($hitcounter, r);
$dat = fread($fil, filesize($hitcounter));
echo $dat+1;
fclose($fil);
$fil = fopen($hitcounter, w);
fwrite($fil, $dat+1);
}

else
{
$fil = fopen($hitcounter, w);
fwrite($fil, 1);
echo '1';
fclose($fil);
}
?>


Now I tried modifying the scripts with $theuri = $_SERVER['REQUEST_URI'];
for example:
if ( ($theuri =="/n/v.htm") ) {
$hitcounter = "../hitcounter.txt";
} else {
$hitcounter = "hitcounter.txt";
}
But that just further complicated things because it recognized /n/v.htm?id=20 as a totally different page than /n/v.htm and so would mess up.

As you may take notice a got it working for logger.php, but to be frank, I don't feel as though I should have to update these scripts every time I post a new article. Someone please help me. This has been bugging me since 1pm est yesterday :(:(