PDA

View Full Version : Conflicting PHP Code


bluemicrobyte
02-19-2006, 1:20 AM
I have two blocks of PHP code on the same page, and when the first section is on the page, the second section of code gives this error:

Fatal error: [] operator not supported for strings in /home/microbyt/public_html/scripts/counter/counter.php on line 5


The two scripts are completely unrelated.

This is the first bit of code:
<?
ob_start();
$file = "webwatch/links.txt";
$display = 5;
$fh = fopen($file, 'r');

// read first record
$line = fgets($fh);
$i = 0;
while(!feof($fh) && $i < $display)
{

// get rid of Windows line breaks
$line = str_replace("\r\n", "", $line);

// get rid of Unix line breaks
$line = str_replace("\r", "", $line);

$split = strpos($line, " ");
$link = substr($line, 0, $split);
$title = substr($line, $split + 1);

echo "<a href=\"$link\" class=\"footertext\">$title</a>\n";
echo "<br /><hr>";
// read next record
$line = fgets($fh);
$i++;

}
fclose($fh);
ob_end_flush();
?>
And here is the second code:

<?php
$ip = $_SERVER['REMOTE_ADDR'];

$file_ip = fopen('/home/microbyt/public_html/scripts/counter/ip.db', 'rb');
while (!feof($file_ip)) $line[]=fgets($file_ip,1024);
for ($i=0; $i<(count($line)); $i++) {
list($ip_x) = split("\n",$line[$i]);
if ($ip == $ip_x) {$found = 1;}
}
fclose($file_ip);

if (!$found) {
$file_ip2 = fopen('/home/microbyt/public_html/scripts/counter/ip.db', 'ab');
$line = "$ip\n";
fwrite($file_ip2, $line, strlen($line));
$file_count = fopen('/home/microbyt/public_html/scripts/counter/count.db', 'rb');
$data = '';
while (!feof($file_count)) $data .= fread($file_count, 4096);
fclose($file_count);
list($today, $yesterday, $total, $date, $days) = split("%", $data);
if ($date == date("Y m d")) $today++;
else {
$yesterday = $today;
$today = 1;
$days++;
$date = date("Y m d");
}
$total++;
$line = "$today%$yesterday%$total%$date%$days";

$file_count2 = fopen('/home/microbyt/public_html/scripts/counter/count.db', 'wb');
fwrite($file_count2, $line, strlen($line));
fclose($file_count2);
fclose($file_ip2);
}
?>

TimP
02-19-2006, 2:18 AM
It's because the variable $line is used in both scripts.

bluemicrobyte
02-19-2006, 2:26 AM
oh lol. I guess I just do a find --> replace and change $line to something else then :P

Thanks, TimP