Can anyone give me the code to make a simple counter.. that just desplays the numbers as text.. (not a picture)
ThanksSomething like this? (php)
<?
$counter_file = "./counter.dat";
if(!($fp = fopen($counter_file, "r"))) die ("Cannot open file.");
$counter = fread($fp, 25);
fclose($fp);
echo "$counter";
?>place this code at the top of the file u want to have count
<?
$counter_file = "./counter.dat";
if(!($fp = fopen($counter_file, "r+"))) die ("Cannot open file.");
$counter = fread($fp, 25);
$counter++ ;
fwrite($fp,$counter) ;
fclose($fp);
echo "$counter";
?>
or u can put this code in a seperate file and include() this file into the file u want to have counter on.whenever i put this code in, i preview it on a blank php page
12.226.40.198/phpinfo.php (<!-- m --><a class="postlink" href="http://12.226.40.198/phpinfo.php">http://12.226.40.198/phpinfo.php</a><!-- m -->)
It says
Warning: fopen(./counter.dat) [function.fopen]: failed to create stream: No such file or directory in c:\program files\apache group\apache\htdocs\phpinfo.php on line 3
Cannot open file.oops, sorry,
the one I posted just reads the file.
the one tonto posted is the more correct one to use.
and for the error part, you will have to create a blank page and name it "counter.dat". upload it to the same area as your script and it should be ok.Warning: fopen(./counter.dat) [function.fopen]: failed to create stream: No such file or directory in c:\program files\apache group\apache\htdocs\phpinfo.php on line 3
counter.dat is the file ur storing ur counts.
make sure it exists in the right directory
eg not to make things complecated just create a file counter.dat in the same directory where ur script is open it using $counter_file = "counter.dat";
tonto
ThanksSomething like this? (php)
<?
$counter_file = "./counter.dat";
if(!($fp = fopen($counter_file, "r"))) die ("Cannot open file.");
$counter = fread($fp, 25);
fclose($fp);
echo "$counter";
?>place this code at the top of the file u want to have count
<?
$counter_file = "./counter.dat";
if(!($fp = fopen($counter_file, "r+"))) die ("Cannot open file.");
$counter = fread($fp, 25);
$counter++ ;
fwrite($fp,$counter) ;
fclose($fp);
echo "$counter";
?>
or u can put this code in a seperate file and include() this file into the file u want to have counter on.whenever i put this code in, i preview it on a blank php page
12.226.40.198/phpinfo.php (<!-- m --><a class="postlink" href="http://12.226.40.198/phpinfo.php">http://12.226.40.198/phpinfo.php</a><!-- m -->)
It says
Warning: fopen(./counter.dat) [function.fopen]: failed to create stream: No such file or directory in c:\program files\apache group\apache\htdocs\phpinfo.php on line 3
Cannot open file.oops, sorry,
the one I posted just reads the file.
the one tonto posted is the more correct one to use.
and for the error part, you will have to create a blank page and name it "counter.dat". upload it to the same area as your script and it should be ok.Warning: fopen(./counter.dat) [function.fopen]: failed to create stream: No such file or directory in c:\program files\apache group\apache\htdocs\phpinfo.php on line 3
counter.dat is the file ur storing ur counts.
make sure it exists in the right directory
eg not to make things complecated just create a file counter.dat in the same directory where ur script is open it using $counter_file = "counter.dat";
tonto