|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 22:00:01 2025 UTC |
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'; ?>