Jump to content

Setcookie in include file


alex.hughson

Recommended Posts

I wrote a function to check valid cookies on my site, and have it on its own in a .php file

 

when I try to include the file, then call the function, I get an error "Cannot modify header information output started at..."  and then a bunch of things about how the output was started in my include file.

 

I wrote it with the assumption that include was like copying the contents of the included file in at that point.  and when i do a setcookie at the same place within the page, nothing bad happens.  Anybody have an idea how to fix this? I need to use the include file in a bunch of pages in the site.

 

Thanks

 

-Alex

Link to comment
https://forums.phpfreaks.com/topic/110837-setcookie-in-include-file/
Share on other sites

You have to make sure it sets the cookie before any output is done (i.e. an echo or HTML).

 

I had this problem before:

I was using UTF-8 or whatever encoding and it made a character at the top that I didn't see. After I deleted that character it worked (just switch to ANSI encoding).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.