Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

sending "Last-Modified" Header can cause E_Warning

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
Spuerhund
Smarty Rookie


Joined: 20 Jan 2005
Posts: 16

PostPosted: Fri May 26, 2006 12:15 pm    Post subject: sending "Last-Modified" Header can cause E_Warning Reply with quote

I am currently using Smarty 2.6.13 and request a small improvement:

In the file "Smarty.class.php" between line 1210 and line 1234 there is something like
Code:
 header('Last-Modified: '.$_gmt_mtime);

for all possible scenarios for a request. It only applies when $caching is enabled and $cache_modified_check is set to 1.

But if - due to a bug or some mistake of the programmer - content output has already startet before, the call of the header() function will cause PHP to throw an Error of level E_WARNING.

Code:
<b>Warning</b>:  Cannot modify header information - headers already sent by ...


This could very easily be fixed by adding
Code:
if (!headers_sent()) { ... }

around every header() function call.

I know that this doesn't solve the cause of the problem and that a programmer should better know whether he can start outputing content ... but sometimes it may nevertheless happen and a PHP Error message somewhere in the output can (and probably will) make a whole side invalid XHTML (or whatever format you use) and will even cause some browsers (like Firefox) not to render anything but displaying a very ugly and cryptic error message instead (in XHTML 1.1 strict mode). I think this is even worse than a missing "Last-Modified" header in this case, therefore i suggest to fix it in the next version of Smarty.

Spuerhund


Last edited by Spuerhund on Fri May 26, 2006 12:54 pm; edited 1 time in total
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Fri May 26, 2006 12:25 pm    Post subject: Re: sending "Last-Modified" Header can cause E_War Reply with quote

Spuerhund wrote:
But if - due to a bug or some mistake of the programmer - content output has already startet before, the call of the header() function will cause PHP to throw an Error of level E_WARNING.


then fix said bug or let the programmer fix his mistake.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Spuerhund
Smarty Rookie


Joined: 20 Jan 2005
Posts: 16

PostPosted: Fri May 26, 2006 12:53 pm    Post subject: Re: sending "Last-Modified" Header can cause E_War Reply with quote

Spuerhund wrote:
I know that this doesn't solve the cause of the problem and that a programmer should better know whether he can start outputing content ... but sometimes it may nevertheless happen and a PHP Error message somewhere in the output can (and probably will) make a whole side invalid XHTML (or whatever format you use) and will even cause some browsers (like Firefox) not to render anything but displaying a very ugly and cryptic error message instead (in XHTML 1.1 strict mode). I think this is even worse than a missing "Last-Modified" header in this case, therefore i suggest to fix it in the next version of Smarty.


It is one thing to fix the bug the programmer made. But a different thing to minimize the damage of this mistake and not to &%#& up a whole website because of such a lapse i think.
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Fri May 26, 2006 1:40 pm    Post subject: Reply with quote

IMHO, that is a bad way to fix this problem. It makes the problem near impossible to track down. This error message informs the programmer that he needs to correct something to get the header working again.

Imagine if PHP silently skipped errors, such as when you apply a string function on an array. You'd spend quite some time figuring out whats wrong!
Back to top
View user's profile Send private message Visit poster's website
iamsure
Smarty Rookie


Joined: 02 Feb 2005
Posts: 22

PostPosted: Sat May 27, 2006 7:47 am    Post subject: Reply with quote

[edited]

Last edited by iamsure on Thu Jul 27, 2006 12:37 am; edited 1 time in total
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Sat May 27, 2006 8:18 am    Post subject: Reply with quote

@spuerhund: if you want to send headers after output has already started, then enable output_buffering in your php.ini (see: http://php.net/outcontrol )

@iamsure: we already have this option, it is called cache_modified_check and documented in TFM (see: http://smarty.php.net/manual/en/variable.cache.modified.check.php )
Back to top
View user's profile Send private message Send e-mail Visit poster's website
iamsure
Smarty Rookie


Joined: 02 Feb 2005
Posts: 22

PostPosted: Sat May 27, 2006 9:02 am    Post subject: Reply with quote

[edited]

Last edited by iamsure on Thu Jul 27, 2006 12:37 am; edited 1 time in total
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Sat May 27, 2006 9:35 am    Post subject: Reply with quote

iamsure wrote:
That option gives two responses: Either give the (incorrect!) last modified date header, OR, give an incorrect 304 not-modified header.


wrong. with $smarty->cache_modified_check = false (the default) no header at all are sent.

and BTW: why don't you tell us *what* is wrong with these headers?
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP