简体   繁体   English

session_start()错误

[英]session_start() error

I can't handle this error, please help me. 我无法处理此错误,请帮助我。 It worked on my laptop but did not work on my desktop. 它可以在我的笔记本电脑上工作,但不能在我的台式机上工作。

Why? 为什么?

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at F:\xampp\htdocs\etest\index.php:1) in F:\xampp\htdocs\etest\common\header.php on line 3

The code: 编码:

<?php
ob_start();
session_start();
include("constants.php");
include("includes.php");
?>

Thanks for your kindness! 谢谢你的好心!

In general, when you see "headers already sent" , it means that you are trying to do something that requires an HTTP header to be set, but you have already sent content to the client. 通常,当您看到“标头已发送”时 ,表示您正在尝试执行一些需要设置HTTP标头的操作,但是您已经将内容发送到了客户端。 When using HTTP, you have to send the headers, then the content comes after. 使用HTTP时,必须发送标头,然后发送内容。 If you've sent content, you've missed your opportunity to send headers. 如果您已发送内容,则错过了发送标头的机会。

the error was at F:\\xampp\\htdocs\\etest\\common\\header.php on line 3 but output was already started at F:\\xampp\\htdocs\\etest\\index.php:1 错误发生在第3行的F:\\xampp\\htdocs\\etest\\common\\header.php on line 3但输出F:\\xampp\\htdocs\\etest\\index.php:1

I assume you posted the header.php, but your index.php either has whitespace before the <?php include() or outputs something other than a header on the first line. 我假设您发布了header.php,但是您的index.php在<?php include()之前有空格,或者在第一行中输出的不是标题。

the error is caused by line one of index.php, whatever is there. 该错误是由index.php的第一行引起的,无论存在什么。 I'd guess whitespace. 我猜是空格。

use_only_cookies=0 to use_only_cookies=1 in php.ini file php.ini文件中的use_only_cookies=0use_only_cookies=1

I encountered the same problem in xampp 7.0.1 and this fixed it. 我在xampp 7.0.1中遇到了相同的问题,并对此进行了修复。 Read it here . 在这里阅读

Start the session on top of the file. 在文件顶部启动会话。

direct afer the php tag when you make an echo or send some header before you get this errormessage. 在产生此错误消息之前,在进行回显或发送一些标头时,直接使用php标签。

<?php
session_start();
ob_start();
include("constants.php");
include("includes.php");
?>

Enable output buffering by configuration. 通过配置启用输出缓冲。 This way it will start before anything else, so it certainly solves your problem. 这样,它将首先开始,因此它肯定可以解决您的问题。 Although you should look at your code and find the cause of the present error, because it seems you do not fully understand your site yet. 尽管您应该查看代码并找到导致当前错误的原因,但因为您似乎还不完全了解您的网站。

After enabling output buffering by configuration, you no longer need to call ob_start() manually. 通过配置启用输出缓冲后,您不再需要手动调用ob_start()

Create a file called .htaccess with this content: 使用以下内容创建一个名为.htaccess的文件:

php_flag output_buffering on

... or add this line to your php.ini: ...或将此行添加到您的php.ini中:

output_buffering = On

Yes start the session on top of the file amd make sure you do not have a space before 是的,请在文件顶部启动会话,并确保之前没有空格

<?php

Plus you can call session_start(); 另外,您可以调用session_start(); only one time 只有一次

session_start() must be called before there is ANY other output. 在有任何其他输出之前,必须先调用session_start() The error is telling you that output started on index.php line 1. The call to session_start() must be placed before that. 错误告诉您输出从index.php第1行开始。必须在此之前调用session_start()

Put this code inside includes.php 将此代码放入include.php中

ob_start();
session_start();

And remove the same code from every other page. 并从其他页面删除相同的代码。 Also make sure that in your files there is no whitespace before the initial 另外,请确保文件中的开头没有空格

(specifically you are getting the error because something is wrong on the first line of index.php not of header.php) (特别是您收到错误,因为在index.php的第一行而不是header.php的第一行有问题)

I was getting this even when I had it at the top of the file. 即使将其放在文件顶部,我也得到了它。

Problem INVISIBLE UTF8 CHARACTER 问题看不见的UTF8字符

Solution Was to delete the file and make a new one starting with <?php and then copy everything after the php into the new one. 解决方案是删除文件并以<?php开头创建一个新文件,然后将<?php之后的所有内容复制到新文件中。 (Don't copy the beginning of the file). (不要复制文件的开头)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM