create a cookie

I am creating a cookie?I am not using any <html> or <head> tags before it.There is only  database connection and retrieving some values from it.I am getting Error as "cookie is Set after header is passed".what is the solution?
padmamvsAsked:
Who is Participating?
 
aikonConnect With a Mentor Commented:
Hi padmamvs,

The cookie code must be before any code you put ei php or html.

Regards.
0
 
maxkirCommented:
check any require() or include() directives before sending a cookie in your text.
I bet that some of the included files outputs some blank characters.

I mean, if you make

include("config.inc");
SetCookie(...);

and file config.inc is like that:
<?php
//stuff
?>
[spaces]
-- end of file --
then these spaces are sent before your SetCookie command - so PHP gives an error.
0
 
tejassCommented:
I completely agree with maxkir
0
All Courses

From novice to tech pro — start learning today.