setcookie("remuser", $HTTP_POST_VARS['m_username'], time()+86400*30); setcookie("rempass", $HTTP_POST_VARS['m_passwd'], time()+86400*30); 我像上面那样写为什么出错了呢?
Warning: Cannot add header information - headers already sent by (output started at c:\apache\htdocs\app\index.php:19) in c:\apache\htdocs\app\index.php on line 129

解决方案 »

  1.   

    首页代码
    $username = getValueByCookies("UNAME");
    if ( $username == "" )
    {
       // 没有记录过}读写cookie的代码如下
    另:我不建议你直接把密码写在cookie里这样不安全
    /**
             * 功能: 设置网站登陆后的cookie
             * 返回值: 成功返回true, 失败返回false
             */
    function setcookies( $username )
    {
                          // expire in half an hour
       return  setcookie("UNAME", $username, time()+7200, "/", "xxx.com");  
    }
    /**
             * 功能: 从cookie中取出指定的值
             * 返回值: 成功该值, 失败返回 ""
             */
    function getValueByCookies( $cookiename )
    {
    $value = isset( $_COOKIE[$cookiename] )? $_COOKIE[$cookiename] : ""; 
    return $value;
    }
      

  2.   

    setcookie("remuser", $HTTP_POST_VARS['m_username'], time()+86400*30); setcookie("rempass", $HTTP_POST_VARS['m_passwd'], time()+86400*30);我像上面那样写为什么出错了呢?
    Warning: Cannot add header information - headers already sent by (output started at c:\apache\htdocs\app\index.php:19) in c:\apache\htdocs\app\index.php on line 129
    写cookie之前不能用页面的输出
      

  3.   

    ChaoticLife() 解释的很全面也很标准了,一般情况下不提倡记录密码,这样如果其他人用了你的计算机,也同样可以登录你的任何帐户,这样安全性不好。