<?
$visitCounter = 0;
if (isset($_COOKIE['visitCounter'])) {
$visitCounter = $_COOKIE['visitCounter'];
$visitCounter++;
}
$lastVisit = '';
if (isset($_COOKIE['lastVisit']))
$lastVisit = date('d-m-Y H:i:s', $_COOKIE['lastVisit']);
if (date('d-m-Y', $_COOKIE['lastVisit']) != date('d-m-Y')) {
setcookie("visitCounter", $visitCounter, 0x7FFFFFFF);
setcookie("lastVisit", time(), 0x7FFFFFFF);
}
if($visitCounter ==1)
echo 'Welcome, new friend!';
else echo 'This is your '.$visitCounter.' visit. Your last visit was at '.$lastVisit.'. Nice to see you again!';
Если стоит:
error_reporting(E_ALL);
ini_set('display_errors', '1');
...код не работает и выдает ошибки:
Notice: Undefined index: lastVisit in C:\OpenServer\domains\localhost\php\cookie.inc.php on line 10
Warning: Cannot modify header information - headers already sent by (output started at C:\OpenServer\domains\localhost\php\cookie.inc.php:10) inC:\OpenServer\domains\localhost\php\cookie.inc.php on line 11
Warning: Cannot modify header information - headers already sent by (output started at C:\OpenServer\domains\localhost\php\cookie.inc.php:10) inC:\OpenServer\domains\localhost\php\cookie.inc.php on line 12
This is your 0 visit. Your last visit was at . Nice to see you again!
Если удалить вывод ошибок - код работает.
Пожалуйста, помогите побороть ошибки.