- PHP code
报错:
您好,您是第一次登录!
Warning: Cannot modify header information - headers already sent by (output started at D:\LAMP\AppServ\www\cookie\lastVisit.php:4) in D:\LAMP\AppServ\www\cookie\lastVisit.php on line 6
------解决方案--------------------
这么改一下代码...另外如果是utf-8 编码文档注意不要有B头
- PHP code
$first = FALSE;
if (empty($_COOKIE['lastVisit'])) {
$first = TRUE;
setcookie("lastVisit", date('Y-m-d H:i:s'), time() + 30 * 24 * 3600);
} else {
$first = FALSE;
setcookie("lastVisit", date('Y-m-d H:i:s'), time() + 30 * 24 * 3600);
}
if ($first) {
echo "您好,您是第一次登录!";
} else {
echo "您上一次访问时间是" . $_COOKIE['lastVisit'];
}
------解决方案--------------------
在header之前有输出导致的,开启缓冲 ob_start();