<?php
setcookie("mr",'MYKYLE');
echo "读取cookie".$_COOKIE['mr'];?>
简单的代码,为什么会报错
Warning: Cannot modify header information - headers already sent by (output started at D:\PHP\index.php:7) in D:\PHP\index.php on line 19

解决方案 »

  1.   

    setcookie前面不能有任何输出。
      

  2.   

    检查<?php前面是否有html代码和空格。。
      

  3.   

    完整代码:
    <!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>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>My kyle</title>
    </head>
    <?php
    setcookie("mr",'MYKYLE');echo "读取cookie".$_COOKIE['mr'];?>
    <body>
    </body>
    </html>
      

  4.   

    前面的HTML就是输出了。。去掉就好了。
      

  5.   

    可以显示,如何在HTML里嵌套,总不能删HTML吧