chapter12.php
<?php
ob_start();
$exam = "我喜欢PHP";
setcookie("text",$exam);
setcookie("text",$exam,time()+1800);
ob_end_flush();
?>
<a href="exam.php">输出Cookie</a>
exam.php
<?php
if(!empty($_COOKIE[text])){
echo "COOKIE值为:".$_COOKIE[text]."<p>";
echo "<a href='exam.del.php'>删除Cookie</a>";
}
else{
echo "Cookie已被删除<P>";
echo "<a href='chapter12.php'>回首页</a>";
}
echo $_COOKIE[text];
?>运行chapter12.php时,为什么老是跳出Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\chapter12.php:9) in C:\AppServ\www\chapter12.php on line 12
Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\chapter12.php:9) in C:\AppServ\www\chapter12.php on line 13
输出Cookie 错误
<?php
ob_start();
$exam = "我喜欢PHP";
setcookie("text",$exam);
setcookie("text",$exam,time()+1800);
ob_end_flush();
?>
<a href="exam.php">输出Cookie</a>
exam.php
<?php
if(!empty($_COOKIE[text])){
echo "COOKIE值为:".$_COOKIE[text]."<p>";
echo "<a href='exam.del.php'>删除Cookie</a>";
}
else{
echo "Cookie已被删除<P>";
echo "<a href='chapter12.php'>回首页</a>";
}
echo $_COOKIE[text];
?>运行chapter12.php时,为什么老是跳出Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\chapter12.php:9) in C:\AppServ\www\chapter12.php on line 12
Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\chapter12.php:9) in C:\AppServ\www\chapter12.php on line 13
输出Cookie 错误
倒是exam.php里的获取COOKIE要加引号,$_COOKIE['text']这样来获取,否则会报错!