|
Posted by Don Freeman on 09/26/12 11:29
"Jofio" <j9k22000@yahoo.com> wrote in message
news:1129573208.355392.108220@g49g2000cwa.googlegroups.com...
> My PHP code to read a simple text file is listed below. What could have
> gone wrong here? When I run it, the browser displays: 'COULD NOT Read'
> opton of the fread() function. I thought the code was OK.
>
>
> <?php
>
> $visitorFile="counter.txt";
> $fh=fopen($visitorFile,"r+") or die("could not open.");
> echo 'Debug 1: opened to read';
> //read from it
> $Visited=fread($fh, filesize($visitorFile)) or die("Could not
> read.");
>
> //Add counter to reflect new count
> $Visited ++;
> //close file
> fclose($fh);
> echo "your are visitor $Visitor";
> ?>
>
>
I don't know what system you are on but for fread() the manual states:
On systems which differentiate between binary and text files (i.e. Windows)
the file must be opened with 'b' included in fopen() mode parameter.
$handle = fopen($filename, "rb");
I just use the following code for my counter:
<?php
$count_for_page = ("hitcounter.txt");
$hits = file($count_for_page);
$hits[0]++;
$fp = fopen($count_for_page, "w");
fputs($fp, "$hits[0]");
fclose($fp);
echo $hits[0];
?>
-Don
--
Ever had one of those days where you just felt like:
http://cosmoslair.com/BadDay.html ?
Navigation:
[Reply to this message]
|