【问题标题】:Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent [duplicate]警告:session_start() [function.session-start]:无法发送会话缓存限制器 - 标头已发送 [重复]
【发布时间】:2013-09-11 06:48:01
【问题描述】:

我的 php 代码出现如下错误:

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home4/iamden83/public_html/loop/signup.php:1) in /home4/iamden83/public_html/loop/signup.php on line 2

代码是这样的

<?php
session_start();
// If user is logged in, header them away
if( isset( $_SESSION["username"] ) ){
    header( "location: message.php?msg=NO to that weenis" );
    exit();
}
?><?php
// Ajax calls this NAME CHECK code to execute
if(isset($_POST["usernamecheck"])){
    include_once("php_includes/db_conx.php");
    $username = preg_replace('#[^a-z0-9]#i', '', $_POST['usernamecheck']);
    $sql = "SELECT id FROM users WHERE username='$username' LIMIT 1";
    $query = mysqli_query($db_conx, $sql); 
    $uname_check = mysqli_num_rows($query);
    if (strlen($username) < 3 || strlen($username) > 16) {
        echo '<strong style="color:#F00;">3 - 16 characters please</strong>';
        exit();
    }
    if (is_numeric($username[0])) {
        echo '<strong style="color:#F00;">Usernames must begin with a letter</strong>';
        exit();
    }
    if ($uname_check < 1) {
        echo '<strong style="color:#009900;">' . $username . ' is OK</strong>';
        exit();
    } else {
        echo '<strong style="color:#F00;">' . $username . ' is taken</strong>';
        exit();
    }
}

【问题讨论】:

    标签: php


    【解决方案1】:

    hmmm,我认为&lt;?php之前一定有一些ascii或空白字符隐藏,只需打开记事本,从session_start()复制内容;到最后粘贴,现在手动添加&lt;?php,并确保第1行&lt;?php之前没有任何空白字符

    【讨论】:

    • 完美答案 :) 帮助了我
    【解决方案2】:

    在页面顶部使用ob_start();,作为输出缓冲区,可以解决这个问题。

    【讨论】:

    • 你救了我,伙计!非常感谢
    猜你喜欢
    • 2011-11-14
    • 2014-06-24
    • 2018-01-29
    • 2016-05-28
    • 2014-06-04
    • 2020-07-02
    • 1970-01-01
    • 1970-01-01
    • 2016-12-14
    相关资源
    最近更新 更多