Simplify my PHP code
Posted: Sat Jun 19, 2004 3:34 pm
I created a web counter to count a user only once per session. I think I may have done things the long way, lol. Tell me what you think.
[edit=Weirdan] use
Code: Select all
<?php
session_start();
if (!session_is_registered("counted")){
$fp = fopen("count.txt", "r");
$count = fgets($fp);
$count = $count + 1;
fclose($fp);
$fp = fopen("count.txt", "w");
fwrite($fp, "$count");
fclose($fp);
session_register("counted");
}
$fp = fopen("count.txt", "r");
$count = fgets($fp);
print "$count";
?>Code: Select all
tags to make your code readable [/edit] [/color]