php 警告:session_start() [function.session-start]:无法发送会话缓存限制器 - 标头已发送
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18670132/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent
提问by Dennis Paler
I received an error on my php code something like this:
我在我的 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
And the code is this
代码是这样的
<?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();
}
}
回答by Beep.exe
hmmm, i think there must be some ascii or white-space character hiding before <?php
, just open notepad, copy content from session_start(); to the end and paste it, now manually add <?php
, and make sure there aren't any white space characters before <?php
at line no 1
嗯,我认为之前一定有一些 ascii 或空白字符隐藏<?php
,只需打开记事本,从 session_start() 复制内容;最后并粘贴它,现在手动添加<?php
,并确保<?php
在第 1 行之前没有任何空格字符
回答by khan
use ob_start();
at the top of the page , its for output buffer and may be solve this problem.
ob_start();
在页面顶部使用,它用于输出缓冲区,可能会解决这个问题。