PHP。 session_start()[function.session-start]:无法发送会话cookie错误

时间:2011-12-24 08:39:53

标签: php

我在我的网站上遇到问题,它在我的本地服务器上完美运行,这是一个WAMPSERVER我可以完全运行我的网站但是在添加到网络服务器后它给我错误说

警告:session_start()[function.session-start]:无法发送会话cookie - 已经在/ home中发送的输出(/home/multisl/public_html/udrivetest/index.php:2中的输出)第4行/multisl/public_html/udrivetest/init.php

的init.php

  <?php

ob_start();
session_start();

   mysql_connect("localhost","***","***");
   mysql_select_db('****');

   include 'function/user.func.php';
   include 'function/car.func.php';
   include 'function/image.func.php';

   ?>

header1.php

<head>
  <title></title>
  <link href="css/style.css" rel="stylesheet" type="text/css">

<style type="text/css">
    <!--
    .style4 {
        font-size: 16px;
        font-weight: bold;
    }
.style5 {
    font-size: 12px
}

.a {
    color:#000000;
    text-decoration:none;
}
-->
</style>

</head>
<body>

 <div style="margin-left:10px;">U Drive.lk</div>

<div class="style5" style="text-align:right; padding:10px;">
        Contact Us | Disclaimer | Site Map</div>
</div>
<div>
    <div style="background-image:url(images/Car3.png); border:#FFFFFF; border-style:solid; border-width:2px; border-top:none; border-bottom:none; width:920px; height:450px;  margin-left:auto; margin-right:auto;" align="center">
        <br/>

        <img src="images/Car6.png" width="920px" height="135px" />
        <div style="margin-top:-22px; height:22px; margin-left:55px;" align="left"><a  class="a">Home</a></div>
        <div style="margin-top:-22px;  height:22px; margin-left:200px;" align="left"><a  class="a">Gallery</a></div>
        <div style="margin-top:-22px;  height:22px; margin-left:350px;" align="left"><a class="a">Leasing</a></div>
        <div style="margin-top:-22px;  height:22px; margin-left:490px;" align="left"><a  class="a">Testimonial</a></div>
        <div style="margin-top:-22px;  height:22px; margin-left:640px;" align="left"><a  class="a">Forum</a></div>
        <div style="margin-top:-22px;  height:22px; margin-left:790px;" align="left"><a class="a">FAQ</a></div>
    <div style="margin-left:auto; margin-right:auto; margin-top:20px;" >
        <script type="text/javascript">
            AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','920','height','135','src','Flash/Flash Header2','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','Flash/Flash Header2' ); //end AC code
        </script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="920" height="135">
            <param name="movie" value="Flash/Flash Header2.swf" />
            <param name="quality" value="high" />
            <embed src="Flash/Flash Header2.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="920" height="135"></embed>
        </object></noscript>
    </div>

    <div align="left">
        <table width="100%" border="0" style="margin-top:10px;">
            <tr>
                <td width="20%" valign="top" ><div align="left"><img src="images/Buy_men.png" /> <img src="images/Sell_men.png" /> <img src="images/Rent_men.png" /></div>
                  <div style="color:#FFFFFF;margin-top:-90px; width:38px; margin-left:10px;"><a href="displayVehicle.php" style="color:#FFFFFF;">Buy</a></div>
                    <div style="color:#FFFFFF;margin-top:-18px; width:38px; margin-left:65px;"><a href="submitCar.php" style="color:#FFFFFF;">Sell</a></div>
                    <div style="color:#FFFFFF;margin-top:-20px; width:38px; margin-left:115px;"><a style="color:#FFFFFF;">Rent</a></div></td>
                <td width="38%"><fieldset style="background-color:#cccccc">
                        <span class="style4">Quick Search</span>

                    </fieldset></td>
                <td width="42%"><fieldset style="background-color:#cccccc">
                        <span class="style4">Login</span>
                     <?php include_once('login.php'); ?>
                    </fieldset></td>
            </tr>
        </table>
    </div>

</div>
</div>

<div style="margin-left:auto; margin-right:auto; width:920px;">

的login.php

  <?php
    if (logged_in()) {
    echo '<br/> <a href="personal_ViewPage.php"> View User Profile </a> <br/><a   href="logout.php">Log Out</a>';
    } else {
    ?>
    <form action="" method="post">
        <table width="100%" border="0" style="margin-top:-5px;" >
            <tr>
                <td><div align="left">User Name :</div></td>
                <td><input type="text" name="Quick_Name" size="25"  /></td>
            </tr>
            <tr>
                <td><div align="left">Password :</div></td>
                <td> <input type="text" name="PassWord" size="25"  />&nbsp;<input type="submit" value="Submit" /></td>
            </tr>
        </table>
    </form>
    <a href="forgotPassword.php">Forgot your password </a>/ <a href="user_Register.php">Register User</a>
    <?php
}
if (isset($_POST['Quick_Name'], $_POST['PassWord'])) {
    $forgotEmail = $_POST['Quick_Name'];
    $login_password = $_POST['PassWord'];

    if (empty($forgotEmail) || empty($login_password)) {
        $errors[] = 'Email and Password required';
    } else {
        $login = login($forgotEmail, $login_password);

        if ($login === false) {
            $errors[] = 'Unable to Log you in';
        }
    }

    if (!empty($errors)) {
        foreach ($errors as $error) {
            echo $error, '<br/>';
        }
    } else {
        $_SESSION['user_id'] = $login;
        header('Location:index.php');
        exit();
    }
     }
    ?>

的index.php

 <?php include 'init.php'; include 'widgets/header1.php'; ?>

 <div>
     </div>
</div>

</body>
</html>

请任何人帮我解决这个问题,或者让我知道我在这里做什么?

先谢谢

3 个答案:

答案 0 :(得分:3)

这很可能是在session_start命令之前发送了一些空格,尝试删除结束的PHP标记(?&gt;)并报告结果。 通过这样做,您可以删除输出任何无效空格的可能性。

答案 1 :(得分:3)

在PHP中,一旦页面开始打印,就会发送标题 - 这可能是由于空格而无意中发生的。

根据您的错误消息(输出从/home/multisl/public_html/udrivetest/index.php:2开始)

我猜这行index.php:

<?php include 'init.php'; include 'widgets/header1.php'; ?>

出现在文件的第2行?但是你不能在它上面有一行空格,它需要是第1行,因为其中一个包含处理标题(会话的cookie)。

否则空白行1是“打印东西” - 一个新行 - 可能在您打算之前发送标题。

基本上,检查所有文件在开始标记<?php上方没有空白行,并且在结束标记?>下面没有空行。

答案 2 :(得分:0)

应该有一些空白空间发送回客户端。保留php结束标记是一个好习惯吗?&gt;如果您的最后一行代码是PHP代码。

确保在php开始标记和php结束标记

之前和之后不要留下任何空格

您可以使用ob_start()使用对象缓冲来阻止任何输出发送到客户端。 把ob_start放在php代码的最开头可以节省你的时间。

我想考虑将init.php中的ob_start()删除为index.php。

感谢

相关问题