[PHP] Cookies in non-frame sites

2006-02-26 Thread emil

Hello,

Most sites today seems to be based on this style:

include(top);
include(current_page);
include(bottom);

If one wants to set cookies from current_page, how should that be handled with 
as clean source as possible?
Before I had the top and bottom output as functions that are called from each 
page, so I can call header stuff before it's executed. But it's not a very good 
looking approach.

I did it like this in every page:
include(top_bottom_lib);
// cookie stuff
echo getTopPage();
// page stuff
echo getBottomPage();

I hope you understand my problem.

Thanks

Best regards Emil

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Cookies in non-frame sites

2006-02-26 Thread chris smith
 Most sites today seems to be based on this style:

 include(top);
 include(current_page);
 include(bottom);

 If one wants to set cookies from current_page, how should that be handled 
 with as clean source as possible?

From the php manual:

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 html and
head tags as well as any whitespace. If output exists prior to
calling this function, setcookie() will fail and return FALSE.

So it has to go before ALL output otherwise it will fail. You're stuck
with putting it in the 'top' file or at least before you echo any
output.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php