php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #788 SetCookie will not work with whitespace leading the <SCRIPT language="php"> tag
Submitted: 1998-09-25 14:58 UTC Modified: 1998-09-25 15:09 UTC
From: mavpion at usa dot net Assigned:
Status: Closed Package: Performance problem
PHP Version: 3.0.4 OS: Linux
Private report: No CVE-ID: None
 [1998-09-25 14:58 UTC] mavpion at usa dot net
this script:
        <SCRIPT language="php">
SetCookie("TestCookie","foobar");
</Script>

Produces the error:
Oops, php3_SetCookie called after header has been sent 

whereas this script: 
<SCRIPT language="php">
SetCookie("TestCookie","foobar");
</Script>

works.

Apparently the leading whitespace causes a header to be sent, making the cookie not work. Can you change this behavior? I am in the habit of right justifying the <script> tag, but if I want to use cookies, I must left justify it.

Thanks

--Eric Guenterberg

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1998-09-25 15:09 UTC] zeev
Anything outside PHP code blocks is considered as raw HTML,
and is sent as-is, untouched by the language engine.  PHP
makes no distinction between whitespace and text, and that's
why your tab, or series of spaces, is considered an HTML
block which triggers the sending of the HTTP header.  This
behavior will not change in PHP 3.0.

In PHP 3.1, there'll be an optional switch to buffer all
output, and only send the HTTP header after the entire
file is parsed, so you'd be able to add in header information,
such as HTTP cookies, even after you output HTML.  Version
3.1 is still way off though.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Mon Aug 03 12:01:24 2020 UTC