为什么include()不允许工作setcookie?

Sim*_*mon 4 php

我需要在我的页面中设置cookie,但它会返回

Warning: Cannot modify header information - headers already sent by (output started at /home1/bsam/public_html/24kadr/index.php:1) in /home1/bsam/public_html/24kadr/basic_login.php  on line 35
Run Code Online (Sandbox Code Playgroud)

在第1行我有

include 'basic_login.php'; 
Run Code Online (Sandbox Code Playgroud)

但即使我删除include,ir也会在session_start或mysql_connect上返回相同的警告.所以我认为这些函数在调用时都使用标题,但我该怎么办?至少我需要连接到数据库,就在它之后我需要使用setcookie().那我该怎么办?谢谢

更新index.php的第一行

<?include 'basic_login.php';include 'settings.php';?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
...........
Run Code Online (Sandbox Code Playgroud)

在basic_login.php中它启动

<?
session_start();
include 'connect.php';
ini_set("session.bug_compat_42",1);
ini_set("session.bug_compat_warn",0);
Run Code Online (Sandbox Code Playgroud)

..........................................

setcookie("cookname", $_SESSION['username'], time()+60*60*24*30, "/");
setcookie("cookpass", $_SESSION['password'], time()+60*60*24*30, "/");
Run Code Online (Sandbox Code Playgroud)

Pek*_*ica 6

你很可能/24kadr/index.php在开幕前有空白区域<?php.删除它应该没问题.

如果没有空格,可能您的PHP文件是使用字节顺序标记(BOM)保存的.在这种情况下,让你的编辑器保存文件没有它.