tags:

views:

70

answers:

4

there is one think, i can't understand anyway:((( when i try to set cookie(it is on line 28 in login.php), browser returns me an error!!!

Cannot modify header information - headers already sent by (output started at C:\xampp2\htdocs\video\index.php:9) in C:\xampp2\htdocs\video\login.php on line 28

but on line 9 in index php, i haven't any header!!! there is a tag!!!
i cant understand it!!! can somebody tall me why it returns me such error?

+1  A: 

You can't print out anything on the site before sending a Header.

abloodywar
i understand!!! thanks
Syom
A: 

Please post some code. What this error means is, that something was already sent (can also be an echo, error notice etc.).

TheCandyMan666
A: 

You have to have your header functions at the very top of your application. Like basically the first lines are for header();

JonnyLitt
Aka, you also can only setcookie either if you are setting it before output starts or you are using an output buffer.
JonnyLitt
+1  A: 

Cookies are sent as headers. From the PHP docs for setcookie:

setcookie() defines a cookie to be sent along with the rest of the HTTP headers. Like other headers, cookies must be sent before any output from your script (this is a protocol restriction). This requires that you place calls to this function prior to any output, including and tags as well as any whitespace.

Also, if your page is saved in UTF-8 format, the BOM (Byte Order Mark) will stop you from being able to set any headers, as it counts as output. See http://bugs.php.net/bug.php?id=22108. To get around this you need to save your file without the byte order mark.

See also: Byte order mark#Unwanted BOMs - Wikipedia

Andy E