这是网上下的代码:
<!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=gb2312" />
<title>银子留言板 Version 1.0</title>
</head>
<link href="css.css" rel="stylesheet" type="text/css" />
<body>
<div id="head">
    <div id="head_l">
        <ul>
            <li><a href="index.php">偶要看留言</a></li>
            <li><a href="post.php">偶要发表</a></li>
            <?php
            session_start();
            if($_SESSION["key"]==1){//如果获取的SESSION为1则显示管理项
            ?>
            <li><a href="adminexit.php">退出管理</a></li>
            <?
            }
            else
            {
            ?>
            <li><a href="admin.php">偶要管理</a></li>
            <?}?>
        </ul>
    </div>
    <div id="head_r">银子留言板 Version 1.0</div>
</div>
运行时报错:Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at E:\apache\Apache2\sites\header.php:11) in E:\apache\Apache2\sites\header.php on line 15Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at E:\apache\Apache2\sites\header.php:11) in E:\apache\Apache2\sites\header.php on line 15谢谢各位了!

解决方案 »

  1.   

    session_start()前面不能显示任何东西,否则就会出错
      

  2.   

    我晕,你session_start();前面有一大段html代码,能不报错吗?这样就OK了<?php session_start();?>
    <!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=gb2312" />
    <title>银子留言板 Version 1.0 </title>
    </head>
    <link href="css.css" rel="stylesheet" type="text/css" />
    <body>
    <div id="head">
        <div id="head_l">
            <ul>
                <li> <a href="index.php">偶要看留言 </a> </li>
                <li> <a href="post.php">偶要发表 </a> </li>
                <?
                if($_SESSION["key"]==1){//如果获取的SESSION为1则显示管理项
                ?>
                <li> <a href="adminexit.php">退出管理 </a> </li>
                <?
                }
                else
                {
                ?>
                <li> <a href="admin.php">偶要管理 </a> </li>
                <?}?>
            </ul>
        </div>
        <div id="head_r">银子留言板 Version 1.0 </div>
    </div> 
      

  3.   

    session_start()必须写在页面的顶部!
    这是网上下的代码:
    <?php session_start(); ?>
    !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=gb2312" />
    <title>银子留言板 Version 1.0 </title>
    </head>
    <link href="css.css" rel="stylesheet" type="text/css" />
    <body>
    <div id="head">
        <div id="head_l">
            <ul>
                <li> <a href="index.php">偶要看留言 </a> </li>
                <li> <a href="post.php">偶要发表 </a> </li>
                <?php
                if($_SESSION["key"]==1){//如果获取的SESSION为1则显示管理项
                ?>
                <li> <a href="adminexit.php">退出管理 </a> </li>
                <?
                }
                else
                {
                ?>
                <li> <a href="admin.php">偶要管理 </a> </li>
                <?}?>
            </ul>
        </div>
        <div id="head_r">银子留言板 Version 1.0 </div>
    </div>
      

  4.   

    session_start()之前莫要有任何输出,utf-8文件的还要注意有文件无bom头。