php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #21046 Cookies not set (setcookie) after invoking an unset variable
Submitted: 2002-12-16 10:05 UTC Modified: 2003-01-27 22:31 UTC
Votes:14
Avg. Score:3.4 ± 1.3
Reproduced:8 of 9 (88.9%)
Same Version:2 (25.0%)
Same OS:3 (37.5%)
From: alexweb at satoridesign dot com Assigned:
Status: No Feedback Package: Output Control
PHP Version: 4.3.0RC3 OS: linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: alexweb at satoridesign dot com
New email:
PHP Version: OS:

 

 [2002-12-16 10:05 UTC] alexweb at satoridesign dot com
If a script generates a php notice (which is logged, not displayed to the screen) something gets output anyway; this output can prevent setting cookies. 
<?
         if (!$undefinedVariable) {
                 if (setcookie ("code","123456")) {
                         print "Cookie set";
                 } else {
                         print "Could not set cookie";
                 }
         }
?>

We get the following in the server log:

PHP Notice:  Undefined variable:  undefinedVariable in
/home/www/dev/pLogin.php on line 2
PHP Warning:  Cannot modify header information - headers already sent in /home/www/dev/pLogin.php on line 3

However, if you add the line

   $undefinedVariable = false;

so that the notice goes away, PHP will happily set the cookie.
display_errors = off, error_reporting = E_ALL, log_errors = On.

Note: This happens on 4.3.0RC2; unfortunately, I could not test on RC3.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-12-16 10:35 UTC] iliaa@php.net
In the same directory as your script put a script with
<?php phpinfo(); ?>
Then in the output of that script check what the display_errors is set to, it is possible that you are either using the wrong .ini file, httpd.conf overwriting your settings for the virtual host or you have .htaccess that changes display_errors to On.

So far, neither I nor other developers who have tried to replicate the problem you've described were able to do so.
 [2002-12-16 10:36 UTC] msopacua@php.net
Could you try this version instead, and report the output?

<?
error_reporting(E_ALL);
if (!$undefinedVariable) {
if (setcookie ("code","123456")) {
print "Cookie set, ";
} else {
print "Could not set cookie, ";
}
}
print (ini_get('log_errors')) ? 'log errs on, ' : 'log errs off';
print (ini_get('display_errors')) ? 'display errs on' : 'display_errs off';
?>
 [2002-12-16 11:23 UTC] alexweb at satoridesign dot com
phpinfo() reports that display_errors is off.  Running the script that msopacua@php.net suggested produces the output:

Could not set cookie, log errs on, display_errs 

Also, php is running as a cgi binary.
 [2002-12-16 13:34 UTC] alexweb at satoridesign dot com
oops, sorry, that should read:
 [2002-12-16 13:35 UTC] alexweb at satoridesign dot com
oops, sorry, that should read: 

Could not set cookie, log errs on, display_errs off
 [2002-12-16 17:18 UTC] iliaa@php.net
What error loging mechanism are you usingl: syslog, file, something else?
 [2002-12-16 20:23 UTC] alexweb at satoridesign dot com
Errors are being logged to the Apache webserver error log for the website. 

We just upgraded to 4.3.0RC3 (CGI version) and the problem still occurs. 

We're using the recommended php.ini file that came with 4.3.0RC3 source.  Running Redhat 6.x, Apache 1.3.2x
display_errors = Off, log_errors = On
 [2003-01-14 19:12 UTC] sniper@php.net
I can not reproduce this with PHP 4.3.0 (Apache DSO) and using the php.ini-recommended as php.ini.

Does this only happen with PHP running as CGI?

 [2003-01-27 22:31 UTC] sniper@php.net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC