มันขึ้นแบบนี้ครับ
Cannot modify header information - headers already sent by (output started at C:\AppServ\www\setcookie.php:1) in C:\AppServ\www\setcookie.php on line 14
นี่โค๊ด
<?php
if(isset($_POST["send"])){
process();
}
else
{
htmlblock();
}
function process(){
$id=$_POST["username"];
if($_COOKIE["username"]=="")
{
setcookie("username",$id,time()+3600);
echo "ขอต้อนรับสู่ระบบคุณ $id <br>";
echo "ตอนนี้คุณยังไม่มี cookie";
}
else
{
echo "ขอต้อนรับสู่ระบบคุณ $user <br>";
echo "คุณมี cookie แล้วคือ".$_COOKIE["username"];
}
}
function htmlblock(){
$id="";
if(isset($_COOKIE["username"])){
$id=$_COOKIE["username"];
}
echo <<<HTML
<form action="{$_SERVER['PHP_SELF']}" method="POST">
<input type="text" name="username" value="{$id}"><br>
<input type="submit" name="send">
</form>
HTML;
}
?>
