-1

Possible Duplicate:
Cannot send session cookie - headers already sent
Headers already sent by PHP

My previous problem was for UTF-8 but now ! again my code generates this error :

Warning: Cannot modify header information - headers already sent by (output started at F:\xampp\htdocs\1\error_list.php:34) in F:\xampp\htdocs\1\error_list.php on line 75

why?

my code is :

header("location:list.php?msg=Please enter some username and password");
Community
  • 1
  • 1
Freeman
  • 9,464
  • 7
  • 35
  • 58

2 Answers2

-1

There are several things 'wrong' with your code:

  1. Don't use shorttags. They aren't really wrong but I don't like them :)
  2. I think your define should be: define('ADMIN', $_SESSION['name']);
  3. You problem either comes up because there is already some html or anything (space) outputted to the browser. If you have saved the file as UTF-8 you should make sure it doesn't include a BOM
PeeHaa
  • 71,436
  • 58
  • 190
  • 262
-2

This happen when you send html code even a single space to the browser. If you have any html code before this php code, so that the problem.

Solution

To tell the browser to buffer everything except php codes, you need to use:

ob_start();

when browser read the the function, it will buffer everything and never send it to the browser until your php code has done its task.

EDIT

Well, If you have some html code before your php code, what do you wanna do? Is there any thing you can do? This a workaround for the problem, why not???

Alireza
  • 6,497
  • 13
  • 59
  • 132
  • 3
    Dirtiest solution possible to solve these errors. -1 – Tom van der Woerdt Dec 25 '11 at 13:53
  • save your breath dude. when you say that, it means you know nothing about anything. give some advice rather than spraying your words..@TomvanderWoerdt – Alireza Dec 25 '11 at 14:06
  • 1
    I have been writing PHP code for over a decade. I am here to tell you this is an awful solution that treats only the symptom, leaving the application broken. The *correct* solution is to re-order your code so that logic occurs before output. As a 99 rep user, maybe you should be less quick to attack others and instead try to *learn* from more experienced developers when they correct you. – user229044 Dec 26 '11 at 05:32
  • I welcome everyone who wants to teach something to me, and I accept his advice with open hands @meager, but If sb just says that's awful, useless and so on it is not going to help. – Alireza Dec 26 '11 at 05:46