Quote:
<?php
$myfile = "visits.txt";
//we assign our file name to the variable we'll use to handle it
if(file_exists($myfile))//if the file exists
{
//we run our counter script
$var = fopen( $myfile,'r+');
//opens in read and write mode our file
$visits = fread($var,filesize($myfile));
//puts the content of the file for its whole lenght
rewind( $var );
//resets the file position indicator to the beginning
$visits++; //increments the actual number of vists by 1
fwrite($var, $visits);
//writes in the variable the actual (incremented) value
fclose($var);//closes our file reference
}
else
{
print "File $myfile doesn't exist...";
Die();
//if the file doesn't exist prompts a warning and kills the script
}
$message = sprintf("%s visitors since 08/20/2005.",$visits);
//saves our visits message in a variable ($message) that will be used as output
print $message;
?>
|
try to get the content by; file_get_contents.
so it will be
Code:
<?php
$myfile = "visits.txt";
//we assign our file name to the variable we'll use to handle it
if(file_exists($myfile))//if the file exists
{
//we run our counter script
$var = fopen( $myfile,\'r+\');
//opens in read and write mode our file
$visits = file_get_contents($myfile);
//puts the content of the file for its whole lenght
rewind( $var );
//resets the file position indicator to the beginning
$visits++; //increments the actual number of vists by 1
fwrite($var, $visits);
//writes in the variable the actual (incremented) value
fclose($var);//closes our file reference
}
else
{
print "File $myfile doesn't exist...";
Die();
//if the file doesn't exist prompts a warning and kills the script
}
$message = sprintf("%s visitors since 08/20/2005.",$visits);
//saves our visits message in a variable ($message) that will be used as output
print $message;
?>
another tip: don't set php scripts after the // too, just start a new line, dont be lazy xD
And, you could even use MySql for this dude, like:
Code:
$get_visits = mysql_query("SELECT * FROM visits");
while($row = mysql_fetch_assoc($get_visits)) {
echo "VISITS: ".$row['amount'];
}
$update_visits = mysql_query("UPDATE visits SET amount = amount+1 ");
something like that, where amount contains the visits amount and the table is called 'visits'.
Good luck.