php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #21569 PHP can't set cookies (setcookie) after invoking an unset variable
Submitted: 2003-01-10 12:55 UTC Modified: 2003-01-14 07:05 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: ElfQrin at ElfQrin dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 4.3.0 OS: Windows
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ElfQrin at ElfQrin dot com
New email:
PHP Version: OS:

 

 [2003-01-10 12:55 UTC] ElfQrin at ElfQrin dot com
PHP can't set cookies on Windows 2000 systems after testing a non-existing variable.

This problem was reported in the following conditions:
- Windows 2000 server SP-3  (IIS not installed)
- Apache v2.0.43 (confirmed on Apache v1.3.27 as well)
- PHP 4.3.0 (confirmed on 4.2.2 and 4.2.3 as well)

The problem happens with Windows 2000 only. On Windows 98 with the very same configuration, or on Linux, everything works fine.

Try the following code:

<?
# $test="X";
setcookie("debug","1",time()+60*60*24*30,"","");
if ($test=="") {setcookie("debug","2",time()+60*60*24*30,"","");}
setcookie("debug","3",time()+60*60*24*30,"","");
?>
<HTML>
<HEAD>
<TITLE>w2k/PHP setcookie bug test</TITLE>
</HEAD>
<BODY>
BEGIN<BR>
<?
echo "Cookie: [".$_COOKIE["debug"]."] (HIT RELOAD)<BR>";
?>
END<BR>
</BODY>
</HTML>

When $test is not set, the cookie "debug" remains set to 1, while when $test is set to any value (including "", an empty string), cookie will be eventually properly set to 3.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-01-13 16:37 UTC] sniper@php.net
There's really no bug here. You're getting a notice about unitialized variable which causes the rest of the headers not to get send. Try adding 'error_reporting(0);' in the beginning of your script..

 [2003-01-14 03:49 UTC] ElfQrin at ElfQrin dot com
I've restored the old php.ini from the previous PHP 4.2.1 installation and the script works fine.

Not a PHP bug, after all, but a configuration issue.
However, since the problem arose I think it deserved to be discussed and solved, even as a "bogus" bug.
 [2003-01-14 06:50 UTC] ElfQrin at ElfQrin dot com
Since PHP returns a notice when an unset variable is invoked, E_NOTICE should be disabled from error_reporting to make scripts work in given conditions:

error_reporting = E_ALL & ~E_NOTICE

Note that since PHP v4.2.2 (?)
error_reporting = E_ALL
is the default
 [2003-01-14 07:05 UTC] msopacua@php.net
no it is not.
The default in E_ALL ~E_NOTICE (see php.ini-dist).

If you use php.ini-recommended, than the default is E_ALL, but also, the default is display_errors Off.

Whichever way you look at it, it is a configuration error envoked by changing something to a non-default.

There's really no justification for the errors in your ways :)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jul 03 20:01:29 2024 UTC