Php 警告:会话_start():无法发送会话cookie-标头已由发送

Php 警告:会话_start():无法发送会话cookie-标头已由发送,php,html,session,cookies,Php,Html,Session,Cookies,我得到这个错误: Warning: session_start(): Cannot send session cookie - headers already sent by Index.php <!-- Session Section --> <?php include 'core/session.php'; ?> <!-- Header Section --> <?php include 'include/header.php'; ?>

我得到这个错误:

Warning: session_start(): Cannot send session cookie - headers already sent by
Index.php

<!-- Session Section -->
<?php include 'core/session.php'; ?>

<!-- Header Section -->
<?php include 'include/header.php'; ?>

<!-- Navigation Section -->
<?php include 'include/navigation_without_logged.php'; ?>

<!-- Content Section -->
<?php include 'include/index_content.php'; ?>

<!-- Footer Section -->
<?php include 'include/footer.php'; ?>

session.php

<?php
if(session_status()!=PHP_SESSION_ACTIVE) {
    session_start();
}
error_reporting(0);

//finding the page the user is currently on
$current_page = end(explode('/', $_SERVER['SCRIPT_NAME']));

?>

header.php

<!DOCTYPE html>
<html lang="en">
<head>
    <title>TEST</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta charset="utf-8">
    <meta name="keywords" content="Electrician Responsive web template, Bootstrap Web Templates, Flat Web Templates, Android Compatible web template,
Smartphone Compatible web template, free webdesigns for Nokia, Samsung, LG, SonyEricsson, Motorola web design" />
    <script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script>
    <!-- bootstrap-css -->
    <link href="assets/css/bootstrap.css" rel="stylesheet" type="text/css" media="all" />
    <!--// bootstrap-css -->
    <!-- css -->
    <link rel="stylesheet" href="assets/css/style.css" type="text/css" media="all" />
    <link rel="stylesheet" href="assets/css/flexslider.css" type="text/css" media="screen" property="" />
    <!--// css -->
    <!-- font-awesome icons -->
    <link rel="stylesheet" href="assets/css/font-awesome.min.css" />
    <!-- //font-awesome icons -->
    <!-- font -->
    <link href="//fonts.googleapis.com/css?family=Josefin+Sans:100,100i,300,300i,400,400i,600,600i,700,700i" rel="stylesheet">
    <link href='//fonts.googleapis.com/css?family=Roboto+Condensed:400,700italic,700,400italic,300italic,300' rel='stylesheet' type='text/css'>
    <!-- //font -->
    <script type="text/javascript" src="assets/js/jquery-2.1.4.min.js"></script>
    <script src="assets/js/main.js"></script>

    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <![endif]-->

</head>

试验
addEventListener(“加载”,函数(){setTimeout(hideURLbar,0);},false);函数hideURLbar(){window.scrollTo(0,1);}
以下是我得到的错误:

警告:session_start():无法发送会话cookie-已由第9行/home/jomingeo/public_html/tradeschool/index.php中的/home/jomingeo/public_html/tradeschool/core/session.php发送的头(输出从/home/jomingeo/public_html/tradeschool/index.php:2开始)

警告:session_start():无法发送session cache limiter-第9行/home/jomingeo/public_html/tradeschool/index.php中已发送的头文件(输出从/home/jomingeo/public_html/tradeschool/core/session.php:2开始)

欢迎提供任何帮助,我希望我已经描述了足够多的问题,如果没有,请询问,我可以分享更多信息。
提前感谢:)

问题正是它所说的。您刚刚将
输出到浏览器,因此无法再设置标题。改为使用PHP注释而不是HTML注释

<?php
// Session Section
include 'core/session.php';

// Header Section
include 'include/header.php';

// Navigation Section
include 'include/navigation_without_logged.php';

// Content Section
include 'include/index_content.php';

// Footer Section
include 'include/footer.php';

这是PHP会话新手最恼火的错误之一

PHP使用浏览器cookie管理会话-cookie标识单个浏览器会话特有的会话id。它首先通过设置一个cookie,在时机成熟时发送到浏览器

Cookie是放置在HTTP(S)消息头部分的数据。PHP在开始写入主体后不会添加到头中

意外写入正文的一种方法是在HTML中使用空行。这被视为输出,将阻止PHP向标头写入更多内容

检查所有文件,尤其是包含的文件中是否有空行。这应该可以解决问题

检查这个

如果在
session_start()之前有任何html输出所以您必须在页面顶部启动对象

在页面顶部添加此行

// Start a object
<?php ob_start(); ?>
//启动一个对象

在我发布之前,我已经查看了其他地方,但我似乎无法解决问题。啊,是使用注释导致了问题