473,322 Members | 1,501 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Yet Another "session_start() Cannot send session cache limiter - headers already sent" Question

I'm somewhat of a newbie to PHP coding, but have developed a site
using the technology, and have been pleasantly surprised by the
capabilities offered. I am more comfortable in the ASP world, however
and am really struggling with managing sessions in PHP, based on my
experiences with managing sessions in ASP.

99.9% of the feedback I have seen when dealing with the errors has
referred to having whitespace before the <?php or after the ?>. I
have opened my source in several different editors and can't find that
to be the case with my code. Aside from having general issues with
the basic methodology in which I am managing sessions, I am completely
perplexed as to why I am getting these errors, from time to time...

For those who might have recommendations on an overall session
management strategy, I basically want to allow my user to come into my
site, through any page that might be bookmarked. Not all pages are
going to require a session, but they may be required to have a session
value set in order to perform certain administrative functions (which
requires a successful login), so I would need to check for the
existence of a session value and log them in and set it, if it doesn't
exist...

Now to my specific problem...

I have an include page called master_session.php, which looks like
this (no whitespaces before or after php tags):
=================================
<?php
if (! isset($ADMIN_session)) {
ob_start();
ob_clean();
session_start();
session_register("ADMIN_session");
}
?>
=================================

I have a login page, which looks like this (no whitespace before the
include of master_session)
=================================
<?php require_once($_SERVER['DOCUMENT_ROOT'].'/common/includes/
master_session.php'); ?>
<?php if ($content_identifier == false){
$content_identifier = 'parish';}?>
<? $page_title = "Administration"; ?>
<?php require_once($_SERVER['DOCUMENT_ROOT'].'/common/includes/
master_header.php'); ?>
<?php require_once($_SERVER['DOCUMENT_ROOT'].'/common/includes/
master_nav.php'); ?>
<?php require_once($_SERVER['DOCUMENT_ROOT'].'/common/includes/
bg100.php'); ?>
<!----CONTENT AREA -- PLACE INCLUDE PATH AND FILE NAME BELOW---->
<form name="criteria_form" action="adminvalidation.php" method="post">
<table height="100%" border="0" width="81%" align="center"
background="/common/bkgrnds/bg100.gif"">
<tr>
<td colspan="2" height="40">&nbsp;</td>
</tr>
<? if (${"login"} == "invalid")
echo "The username/password you have entered is invalid, or you do
not have privileges to perform administrative functions. If you feel
you've received this message in error, please contact your system
administrator.";
?>
<tr>
<td colspan="2" align="center"><strong>Please Login</strong></
td>
</tr>
<tr>
<td colspan="2" height="40">&nbsp;</td>
</tr>
<tr>
<td align="right">Username&nbsp;</td>
<td><input type="text" name="user_nm" size="8" maxlength="8">
</td>
</tr>
<tr>
<td align="right">Password&nbsp;</td>
<td><input type="password" name="password" size="10"
maxlength="10">
</td>
</tr>
<tr>
<td colspan="2" height="40">&nbsp;</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit"
name="Submit" value="Submit">
</td>
</tr>
<tr>
<td><input type="hidden" name="content_identifier" value="<?echo
${content_identifier}?>"></td>
</tr>
</table>
</form>
<!----END CONTENT AREA --- NO CHANGES BELOW THIS LINE-------->
<?php require_once($_SERVER['DOCUMENT_ROOT'].'/common/includes/
master_footer.php'); ?>
==============================================

master_header.php is where my HTML code starts:
========================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

etc...................
========================
Is there anything in here that jumps out at anyone, as to why I'm
getting the error? The exact error is:

Warning: session_start() [function.session-start]: Cannot send session
cache limiter - headers already sent (output started at /home/holytrin/
public_html/common/admin/admin.php:2) in /home/holytrin/public_html/
common/includes/master_session.php on line 4

btw.. I do an ob_end_flush() in the master_footer.php file, on the
very last line...

Any help would be greatly appreciated!!!

Best Regards,
Todd

Mar 30 '07 #1
4 5904
three-eight-hotel wrote:
I'm somewhat of a newbie to PHP coding,
<snip>
99.9% of the feedback I have seen when dealing with the errors has
referred to having whitespace before the <?php or after the ?>.
<snip>
<?php
<snip>
<?php require_once($_SERVER['DOCUMENT_ROOT'].'/common/includes/
<snip>

Hi Todd,

You're more likely to get sensible answers to your questions if you try to
keep to the point - read this:

http://www.catb.org/~esr/faqs/smart-questions.html

From what you've posted the most likely causes of the problem are:

1) the BOM marker at the start of a UTF-8 encoded source file - you *must*
save your files as ASCII.

2) an auto-prepend file specified in the php.ini or webserver config.

HTH

C.
Mar 30 '07 #2
On Mar 30, 9:27 pm, "three-eight-hotel" <t...@thepetersonranch.com>
wrote:
I'm somewhat of a newbie to PHP coding, but have developed a site
using the technology, and have been pleasantly surprised by the
capabilities offered. I am more comfortable in the ASP world, however
and am really struggling with managing sessions in PHP, based on my
experiences with managing sessions in ASP.

99.9% of the feedback I have seen when dealing with the errors has
referred to having whitespace before the <?php or after the ?>. I
have opened my source in several different editors and can't find that
to be the case with my code. Aside from having general issues with
the basic methodology in which I am managing sessions, I am completely
perplexed as to why I am getting these errors, from time to time...

For those who might have recommendations on an overall session
management strategy, I basically want to allow my user to come into my
site, through any page that might be bookmarked. Not all pages are
going to require a session, but they may be required to have a session
value set in order to perform certain administrative functions (which
requires a successful login), so I would need to check for the
existence of a session value and log them in and set it, if it doesn't
exist...

Now to my specific problem...

I have an include page called master_session.php, which looks like
this (no whitespaces before or after php tags):
=================================
<?php
if (! isset($ADMIN_session)) {
ob_start();
ob_clean();
session_start();
session_register("ADMIN_session");
}
?>
=================================

I have a login page, which looks like this (no whitespace before the
include of master_session)
=================================
<?php require_once($_SERVER['DOCUMENT_ROOT'].'/common/includes/
master_session.php'); ?>
<?php if ($content_identifier == false){
$content_identifier = 'parish';}?>
<? $page_title = "Administration"; ?>
<?php require_once($_SERVER['DOCUMENT_ROOT'].'/common/includes/
master_header.php'); ?>
<?php require_once($_SERVER['DOCUMENT_ROOT'].'/common/includes/
master_nav.php'); ?>
<?php require_once($_SERVER['DOCUMENT_ROOT'].'/common/includes/
bg100.php'); ?>
<!----CONTENT AREA -- PLACE INCLUDE PATH AND FILE NAME BELOW---->
<form name="criteria_form" action="adminvalidation.php" method="post">
<table height="100%" border="0" width="81%" align="center"
background="/common/bkgrnds/bg100.gif"">
<tr>
<td colspan="2" height="40">&nbsp;</td>
</tr>
<? if (${"login"} == "invalid")
echo "The username/password you have entered is invalid, or you do
not have privileges to perform administrative functions. If you feel
you've received this message in error, please contact your system
administrator.";
?>
<tr>
<td colspan="2" align="center"><strong>Please Login</strong></
td>
</tr>
<tr>
<td colspan="2" height="40">&nbsp;</td>
</tr>
<tr>
<td align="right">Username&nbsp;</td>
<td><input type="text" name="user_nm" size="8" maxlength="8">
</td>
</tr>
<tr>
<td align="right">Password&nbsp;</td>
<td><input type="password" name="password" size="10"
maxlength="10">
</td>
</tr>
<tr>
<td colspan="2" height="40">&nbsp;</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit"
name="Submit" value="Submit">
</td>
</tr>
<tr>
<td><input type="hidden" name="content_identifier" value="<?echo
${content_identifier}?>"></td>
</tr>
</table>
</form>
<!----END CONTENT AREA --- NO CHANGES BELOW THIS LINE-------->
<?php require_once($_SERVER['DOCUMENT_ROOT'].'/common/includes/
master_footer.php'); ?>
==============================================

master_header.php is where my HTML code starts:
========================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

etc...................
========================

Is there anything in here that jumps out at anyone, as to why I'm
getting the error? The exact error is:

Warning: session_start() [function.session-start]: Cannot send session
cache limiter - headers already sent (output started at /home/holytrin/
public_html/common/admin/admin.php:2) in /home/holytrin/public_html/
common/includes/master_session.php on line 4

btw.. I do an ob_end_flush() in the master_footer.php file, on the
very last line...

Any help would be greatly appreciated!!!

Best Regards,
Todd
the essential problem is one of sending a header, response headers
have to be sent before any response body, so whenever you call any
function before session_start() which sends a header, you might have
trouble if the function returns output.
calling session_start first will fix this of course, and it doesnt
affect the use of ob_start() since that is about buffering response
body output.

what you are doing is saying when you call ob_start is "everything
after this point should be captured and stored in the buffer", but
what you then output is a header, something which can be sent first,
and should not be captured.

Mar 30 '07 #3
On Mar 30, 9:27 pm, "three-eight-hotel" <t...@thepetersonranch.com>
wrote:
I'm somewhat of a newbie to PHP coding, but have developed a site
using the technology, and have been pleasantly surprised by the
capabilities offered. I am more comfortable in the ASP world, however
and am really struggling with managing sessions in PHP, based on my
experiences with managing sessions in ASP.

99.9% of the feedback I have seen when dealing with the errors has
referred to having whitespace before the <?php or after the ?>. I
have opened my source in several different editors and can't find that
to be the case with my code. Aside from having general issues with
the basic methodology in which I am managing sessions, I am completely
perplexed as to why I am getting these errors, from time to time...

For those who might have recommendations on an overall session
management strategy, I basically want to allow my user to come into my
site, through any page that might be bookmarked. Not all pages are
going to require a session, but they may be required to have a session
value set in order to perform certain administrative functions (which
requires a successful login), so I would need to check for the
existence of a session value and log them in and set it, if it doesn't
exist...

Now to my specific problem...

I have an include page called master_session.php, which looks like
this (no whitespaces before or after php tags):
=================================
<?php
if (! isset($ADMIN_session)) {
ob_start();
ob_clean();
session_start();
session_register("ADMIN_session");
}
?>
=================================

I have a login page, which looks like this (no whitespace before the
include of master_session)
=================================
<?php require_once($_SERVER['DOCUMENT_ROOT'].'/common/includes/
master_session.php'); ?>
<?php if ($content_identifier == false){
$content_identifier = 'parish';}?>
<? $page_title = "Administration"; ?>
<?php require_once($_SERVER['DOCUMENT_ROOT'].'/common/includes/
master_header.php'); ?>
<?php require_once($_SERVER['DOCUMENT_ROOT'].'/common/includes/
master_nav.php'); ?>
<?php require_once($_SERVER['DOCUMENT_ROOT'].'/common/includes/
bg100.php'); ?>
<!----CONTENT AREA -- PLACE INCLUDE PATH AND FILE NAME BELOW---->
<form name="criteria_form" action="adminvalidation.php" method="post">
<table height="100%" border="0" width="81%" align="center"
background="/common/bkgrnds/bg100.gif"">
<tr>
<td colspan="2" height="40">&nbsp;</td>
</tr>
<? if (${"login"} == "invalid")
echo "The username/password you have entered is invalid, or you do
not have privileges to perform administrative functions. If you feel
you've received this message in error, please contact your system
administrator.";
?>
<tr>
<td colspan="2" align="center"><strong>Please Login</strong></
td>
</tr>
<tr>
<td colspan="2" height="40">&nbsp;</td>
</tr>
<tr>
<td align="right">Username&nbsp;</td>
<td><input type="text" name="user_nm" size="8" maxlength="8">
</td>
</tr>
<tr>
<td align="right">Password&nbsp;</td>
<td><input type="password" name="password" size="10"
maxlength="10">
</td>
</tr>
<tr>
<td colspan="2" height="40">&nbsp;</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit"
name="Submit" value="Submit">
</td>
</tr>
<tr>
<td><input type="hidden" name="content_identifier" value="<?echo
${content_identifier}?>"></td>
</tr>
</table>
</form>
<!----END CONTENT AREA --- NO CHANGES BELOW THIS LINE-------->
<?php require_once($_SERVER['DOCUMENT_ROOT'].'/common/includes/
master_footer.php'); ?>
==============================================

master_header.php is where my HTML code starts:
========================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

etc...................
========================

Is there anything in here that jumps out at anyone, as to why I'm
getting the error? The exact error is:

Warning: session_start() [function.session-start]: Cannot send session
cache limiter - headers already sent (output started at /home/holytrin/
public_html/common/admin/admin.php:2) in /home/holytrin/public_html/
common/includes/master_session.php on line 4

btw.. I do an ob_end_flush() in the master_footer.php file, on the
very last line...

Any help would be greatly appreciated!!!

Best Regards,
Todd
btw, am I to assume you are using ob_start being you are implementing
some kind of compression - if not, then don't bother using it.
Also convert all short tags <? to <?php which is the standard these
days, and will make your scripts easier to port onwards, and when you
finally turn off short tags in the php.ini (or upgrade) you will be
able to use <?xml style declarations without conflicts.
Also I assume you understand about turning globals off, it's just that
if you don't asking questions like
if( $content_identifier == false )
can get you into trouble because later you print that value out (which
you set to parish but could be overridden to something nasty) in the
markup un-filtered.
I should say that I am not in full possession of the facts so it isn't
intended as a -ve critique, more an observation based on what I can
see.

Mar 30 '07 #4
On Mar 30, 4:27 pm, "three-eight-hotel" <t...@thepetersonranch.com>
wrote:
I'm somewhat of a newbie to PHP coding, but have developed a site
using the technology, and have been pleasantly surprised by the
capabilities offered. I am more comfortable in the ASP world, however
and am really struggling with managing sessions in PHP, based on my
experiences with managing sessions in ASP.

99.9% of the feedback I have seen when dealing with the errors has
referred to having whitespace before the <?php or after the ?>. I
have opened my source in several different editors and can't find that
to be the case with my code. Aside from having general issues with
the basic methodology in which I am managing sessions, I am completely
perplexed as to why I am getting these errors, from time to time...

For those who might have recommendations on an overallsession
management strategy, I basically want to allow my user to come into my
site, through any page that might be bookmarked. Not all pages are
going to require asession, but they may be required to have asession
value set in order to perform certain administrative functions (which
requires a successful login), so I would need to check for the
existence of asessionvalue and log them in and set it, if it doesn't
exist...

Now to my specific problem...

I have an include page called master_session.php, which looks like
this (no whitespaces before or after php tags):
=================================
<?php
if (! isset($ADMIN_session)) {
ob_start();
ob_clean();
session_start();
session_register("ADMIN_session");
}
?>
=================================

I have a login page, which looks like this (no whitespace before the
include of master_session)
=================================
<?php require_once($_SERVER['DOCUMENT_ROOT'].'/common/includes/
master_session.php'); ?>
<?php if ($content_identifier == false){
$content_identifier = 'parish';}?>
<? $page_title = "Administration"; ?>
<?php require_once($_SERVER['DOCUMENT_ROOT'].'/common/includes/
master_header.php'); ?>
<?php require_once($_SERVER['DOCUMENT_ROOT'].'/common/includes/
master_nav.php'); ?>
<?php require_once($_SERVER['DOCUMENT_ROOT'].'/common/includes/
bg100.php'); ?>
<!----CONTENT AREA -- PLACE INCLUDE PATH AND FILE NAME BELOW---->
<form name="criteria_form" action="adminvalidation.php" method="post">
<table height="100%" border="0" width="81%" align="center"
background="/common/bkgrnds/bg100.gif"">
<tr>
<td colspan="2" height="40">&nbsp;</td>
</tr>
<? if (${"login"} == "invalid")
echo "The username/password you have entered is invalid, or you do
not have privileges to perform administrative functions. If you feel
you've received this message in error, please contact your system
administrator.";
?>
<tr>
<td colspan="2" align="center"><strong>Please Login</strong></
td>
</tr>
<tr>
<td colspan="2" height="40">&nbsp;</td>
</tr>
<tr>
<td align="right">Username&nbsp;</td>
<td><input type="text" name="user_nm" size="8" maxlength="8">
</td>
</tr>
<tr>
<td align="right">Password&nbsp;</td>
<td><input type="password" name="password" size="10"
maxlength="10">
</td>
</tr>
<tr>
<td colspan="2" height="40">&nbsp;</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit"
name="Submit" value="Submit">
</td>
</tr>
<tr>
<td><input type="hidden" name="content_identifier" value="<?echo
${content_identifier}?>"></td>
</tr>
</table>
</form>
<!----END CONTENT AREA --- NO CHANGES BELOW THIS LINE-------->
<?php require_once($_SERVER['DOCUMENT_ROOT'].'/common/includes/
master_footer.php'); ?>
==============================================

master_header.php is where my HTML code starts:
========================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

etc...................
========================

Is there anything in here that jumps out at anyone, as to why I'm
getting the error? The exact error is:

Warning: session_start() [function.session-start]:Cannotsendsessioncachelimiter- headers already sent (output started at /home/holytrin/
public_html/common/admin/admin.php:2) in /home/holytrin/public_html/
common/includes/master_session.php on line 4

btw.. I do an ob_end_flush() in the master_footer.php file, on the
very last line...

Any help would be greatly appreciated!!!

Best Regards,
Todd
Hi. I've been having the same problem and I just figured it out. You
can't have anything come before the session call (session_start()).
You can't even have a blank line before the "<?php" tag. That's what
happened to me. The session call worked fine on all but one of my
pages. I put session_start() at the very top of my header.php file (<?
php session_start(); ?>), which is on the very first line of each of
my pages (<?php include ('includes/header.php');). However, on one of
my pages, the code looked like this (I added the line numbers to
emphasize the point):

1.
2. <?php include ('includes/header.php');
3. $page_title = 'Title';

I know it sounds stupid, but the problem was that empty line of code
before my <?php tag. I deleted the first line so the code looked like
this:

1. <?php include ('includes/header.php');
2. $page_title = 'Title';

And it works fine.

May 29 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mercy | last post by:
Hi, I'm a newbie. I was trying to figure out how to use the Session_start method? The reference books I'm reading say that a session STARTS when "session_start" is called. But ... in their sample...
1
by: chsakda | last post by:
In my Page_Load Method, I call a method by asynchronous callback to do some work. It's working fine until it calls back. Here is the problem in my callback method. Basically, I cannot redirect...
5
by: Chris Robb | last post by:
I'm having some really odd behavior with a PHP script. I have it populating an HTML select form with a for loop. When I try the years 2006 to 1900. I get the following error: PHP Warning: ...
2
by: monomaniac21 | last post by:
Hi all! How can i get round this. I want to stick an include at the top of my script for the connection to DB and then somewhere below this process a form and if all is good execute a redirect...
19
by: lawrence k | last post by:
How can I find out where my script is outputting to the screen for the first time? My error logs are full of stuff like this: PHP Warning: session_start(): Cannot send session cache...
0
by: miha.valencic | last post by:
Is there a way (int ASP.NET 1.1 or 2.0) to check which "Cache-Control" headers have been output or set before the page is written to output stream? There is Response.Headers property in .NET...
3
by: shybe | last post by:
Ok, Im trying to create a "send this article to a friend" script for my blog, Right now its sending all the articles, but I want it to only send the article in which the form is attached...
2
by: Fred | last post by:
"Warning: session_start() : Node no longer exists in" the call to session_start() on my page. Seemingly, the error comes and goes. From what I've gathered, this is some bug which arises when...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.