Skip to content

Commit

Permalink
Merge pull request #572 from juzna/ob-problem
Browse files Browse the repository at this point in the history
show a warning of possible buffer overflow
  • Loading branch information
dg committed Mar 30, 2013
2 parents 3079a95 + c13ed0e commit 916da72
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Nette/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,10 @@ public function __destruct()
*/
public function setCookie($name, $value, $time, $path = NULL, $domain = NULL, $secure = NULL, $httpOnly = NULL)
{
if (!headers_sent() && ob_get_level() && ob_get_length()) {
trigger_error("Possible problem: you are sending a cookie while already having some data in output buffer. This may not work if the outputted data grows. Try starting the session earlier.", E_USER_NOTICE);
}

if (headers_sent($file, $line)) {
throw new Nette\InvalidStateException("Cannot set cookie after HTTP headers have been sent" . ($file ? " (output started at $file:$line)." : "."));
}
Expand Down
4 changes: 4 additions & 0 deletions Nette/Http/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,10 @@ public function setStorage(ISessionStorage $storage)
*/
private function sendCookie()
{
if (!headers_sent() && ob_get_level() && ob_get_length()) {
trigger_error("Possible problem: you are starting session while already having some data in output buffer. This may not work if the outputted data grows. Try starting the session earlier.", E_USER_NOTICE);
}

$cookie = $this->getCookieParameters();
$this->response->setCookie(
session_name(), session_id(),
Expand Down

0 comments on commit 916da72

Please sign in to comment.