tags:

views:

95

answers:

3

i need to set cookies in my page, but it returns

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

on line 1 i have

include 'basic_login.php'; 

but even if i remoove include, ir returns the same warning on session_start, or mysql_connect. so i think these all functions use header when calling, but what can i do? at least i need to connect to database, and just after it i need to use setcookie(). so what can i do? thanks

update the first lines of 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"&gt;
<html>
<head>
...........

in basic_login.php it starts

<?
session_start();
include 'connect.php';
ini_set("session.bug_compat_42",1);
ini_set("session.bug_compat_warn",0);

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

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

+2  A: 

You get this error if you output anything before the header/cookie is set. Either do it before you output anything, even blank lines, or use output buffering.

Ignacio Vazquez-Abrams
@Ignacio Vazquez-Abrams so when i call include(), it is outputing?what is output buffering, i don't know:(
Syom
Some file you're using somewhere outputs something. Check your files.
Ignacio Vazquez-Abrams
+5  A: 

You most likely have white space in /24kadr/index.php before the opening <?php. Remove it and it should be fine.

If there is no white space, maybe your PHP file was saved with a Byte Order Mark (BOM). In that case, have your editor save the file without it.

Pekka
@Pekka i've remoove ti, but it doesn' help:(
Syom
Can you show the first lines of /24kadr/index.php?
Pekka
@Pekka i've shown. look please
Syom
@Syom maybe the file has a BOM. See the answer to this question: http://stackoverflow.com/questions/1814258/bom-in-a-php-page-auto-generated-by-wordpress on how to remove it.
Pekka
@Syom and it's still the exact same error message, right?
Pekka
@Pekka yes, you're true
Syom
A: 

If you are sure that your file /24kadr/index.php begins with

<?php

with not a single character before then you may be hitting the "UTF-8 with BOM" issue

If your editor is configured to save file with encoding "UTF-8 with BOM" then it will add (and not show) 2 special characters at the beginning of your file.

This can lead PHP to throw the warning.

I hope this will help Jerome WAGNER

Jerome WAGNER