i made a simple webpage for a friend of mine with only 3 pages ... its realy simple.
nothing fancy. i added a php hit counter on the page and now everytime i hit refresh,
the counter gets +1. so i decided to use a cookie.
I read that i have to put the cookie on the top of the page, before any html code, but
i still get "Cannot modify header information ..." error.
I dont know what i am doing wrong.
<?php setcookie ("zadnji_obisk", "obisk", time()+300); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head>
And here is the counter script.
<?php $fil = fopen('stevec.txt', r); $dat = fread($fil, filesize('stevec.txt')); if(isset($_COOKIE['zadnji_obisk'])) { echo $dat; } else { echo $dat+1; fclose($fil); $fil = fopen('stevec.txt', w); fwrite($fil, $dat+1); } ?>
Can anyone point out what i should do?
Regards,
HEki