【问题标题】:PHP. session_start() [function.session-start]: Cannot send session cookie errorphp。 session_start() [function.session-start]:无法发送会话 cookie 错误
【发布时间】:2012-01-27 06:10:51
【问题描述】:

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

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

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>

谁能帮我解决这个问题或给我一个线索我在这里做什么?

提前致谢

【问题讨论】:

标签: php


【解决方案1】:

在 PHP 中,一旦页面开始打印某些内容,就会发送标头 - 由于空格,这可能会无意中发生。

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

我猜是index.php这行:

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

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

否则空行 1 是“打印一些东西”——一个新行——它可能会在你打算之前发送标题。

基本上,检查所有文件在开始标签&lt;?php上方没有空行,在结束标签?&gt;下方没有空行。

【讨论】:

  • 谢谢它完美地工作,正是空白是我面临 2 天的问题..:Dthanx 再次向thanx 提供建议
【解决方案2】:

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

【讨论】:

  • 是的,空白是支持的问题
【解决方案3】:

应该有一些空白空间发送回客户端。如果您的最后一行代码是 php 代码,最好留下 php 结束标记?>。

确保在 php 开始标记和 php 结束标记之前和之后不要留下任何空格

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

我想考虑将 ob_start() 从 init.php 删除到 index.php。

谢谢

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-06-24
    • 2011-11-14
    • 2014-03-22
    • 2013-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多