Hi,
I am trying to make my own counter using PHP, which I thought would be pretty easy for a beginner like me. However on producing the code, I have confused myself on how to make the code.
I am trying to set a session variable called 'COUNTER', which is registered to the session when a visitor goes to my homepage, which in turn should add one to the counter and note the date and time the most recent update was made. Then I have a check, should the return during the current session, then nothing is added to the counter.
I was hoping to store the current counter value in a text file, like I do with my url redirect log.
Here is the current code layout, which is likely to be very wrong!
<?php
session_start();
if (isset($_SESSION['COUNTER'])) {
// null
}
else {
$DataStamp = date("l F j, Y") . " -- " . date("H:i:s");
$File = "counterlog.txt";
$Directory = "log/" . $File;
// read in current integer value $old_value;
// add one to the value $old_value++;
// write new integer value $new_value = $old_value;
$Open = fopen($Directory, "a");
fwrite($Open, "$DataStamp\t$new_value\n");
fclose($Open);
}
session_register("COUNTER");
?>
Can anyone help me.
Thanks,
Mike