ID:               21210
 Updated by:       [EMAIL PROTECTED]
 Reported By:      [EMAIL PROTECTED]
-Status:           Open
+Status:           Feedback
 Bug Type:         Session related
 Operating System: Linux 2.4.7
 PHP Version:      4.2.3
 New Comment:

Do a 'od -c include.php' and see what is at the end of your included
file.  I bet you have extra carriage returns.


Previous Comments:
------------------------------------------------------------------------

[2002-12-26 20:19:44] [EMAIL PROTECTED]

Calling includes or requires seems to create header output, even if the
includes or requires are blank. This conflicts with session handling in
situations where the session is called as a result of logic-branches in
the code.

I have encountered this issue on several different systems.

Here's the setup. 
Create an include file, called "include.php".
Put the following in it:
<?php
?>

Now, create a page with the following code:
<?php
include("include.php");

session_start();
session_register("SESSION");

if (!isset($SESSION)) {
        $SESSION["count"] = 0;
        print("<p>Counter initialized, please reload this page to see
it increment</p>");
} 
else {
        print("<p>Waking up session $PHPSESSID</p>");
        $SESSION["count"]++;
}
print("<p>The counter is now $SESSION[count] </p>");
?>

run the page with all the code in the browser such that it includes the
include file above.

Even though the include file does not write or generate a single
header, the output I get is:
"Warning: Cannot send session cookie - headers already sent by (output
started at include.php:1) in test.php on line 4

Warning: Cannot send session cache limiter - headers already sent
(output started at include.php:1) in test.php on line 4

Counter initialized, please reload this page to see it increment

The counter is now 0 "

My observation is corroborated by the following note, found on the
session_start() function manual page at php.net. 

############
As per <shadowflame at starpilot dot net>:
"If you are using an include page, such as a config or possibly
common-functions page, that relies on session variables being pulled
from the sesssion, remember to add the session_start() function
_before_ you call the includes, or your session will not be called by
the page..."

Any include or require called before you call session_start() will
cause the initial session setup to fail, even if that include file
contains only a comment! 

Here are scenarios:
include("blank_file.php");
session_start();

This works. However:

include("file_with_just_a_comment_in_it.php");
session_start();

Does not.

The recommended way to use session_start() is of course to put it at
the top of the page. However, if, like me, you find yourself wanting to
start a session only as a result of some previous logic, this avenue is
closed to you. You will have to use ob_start() and related functions,
and create a code mess. 

It will be a beautiful day when header conflicts are caused only by the
layout of my code rather than PHP code cruft.
##############

As mentioned, I've encountered this on several different systems, so
configure lines and php.ini doesn't seem to be too relevant. If you
want build lines or php.ini, I'll send them on via e-mail.

------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=21210&edit=1

Reply via email to