473,585 Members | 2,512 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_se ssion)) {
ob_start();
ob_clean();
session_start() ;
session_registe r("ADMIN_sessio n");
}
?>
=============== =============== ===

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_ident ifier == false){
$content_identi fier = 'parish';}?>
<? $page_title = "Administration "; ?>
<?php require_once($_ SERVER['DOCUMENT_ROOT'].'/common/includes/
master_header.p hp'); ?>
<?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="adminva lidation.php" method="post">
<table height="100%" border="0" width="81%" align="center"
background="/common/bkgrnds/bg100.gif"">
<tr>
<td colspan="2" height="40">&nb sp;</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>Pleas e Login</strong></
td>
</tr>
<tr>
<td colspan="2" height="40">&nb sp;</td>
</tr>
<tr>
<td align="right">U sername&nbsp;</td>
<td><input type="text" name="user_nm" size="8" maxlength="8">
</td>
</tr>
<tr>
<td align="right">P assword&nbsp;</td>
<td><input type="password" name="password" size="10"
maxlength="10">
</td>
</tr>
<tr>
<td colspan="2" height="40">&nb sp;</td>
</tr>
<tr>
<td colspan="2" align="center"> <input type="submit"
name="Submit" value="Submit">
</td>
</tr>
<tr>
<td><input type="hidden" name="content_i dentifier" value="<?echo
${content_ident ifier}?>"></td>
</tr>
</table>
</form>
<!----END CONTENT AREA --- NO CHANGES BELOW THIS LINE-------->
<?php require_once($_ SERVER['DOCUMENT_ROOT'].'/common/includes/
master_footer.p hp'); ?>
=============== =============== =============== =

master_header.p hp 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.sessio n-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.p hp file, on the
very last line...

Any help would be greatly appreciated!!!

Best Regards,
Todd

Mar 30 '07 #1
4 5929
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...@thepeters onranch.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_se ssion)) {
ob_start();
ob_clean();
session_start() ;
session_registe r("ADMIN_sessio n");
}
?>
=============== =============== ===

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_ident ifier == false){
$content_identi fier = 'parish';}?>
<? $page_title = "Administration "; ?>
<?php require_once($_ SERVER['DOCUMENT_ROOT'].'/common/includes/
master_header.p hp'); ?>
<?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="adminva lidation.php" method="post">
<table height="100%" border="0" width="81%" align="center"
background="/common/bkgrnds/bg100.gif"">
<tr>
<td colspan="2" height="40">&nb sp;</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>Pleas e Login</strong></
td>
</tr>
<tr>
<td colspan="2" height="40">&nb sp;</td>
</tr>
<tr>
<td align="right">U sername&nbsp;</td>
<td><input type="text" name="user_nm" size="8" maxlength="8">
</td>
</tr>
<tr>
<td align="right">P assword&nbsp;</td>
<td><input type="password" name="password" size="10"
maxlength="10">
</td>
</tr>
<tr>
<td colspan="2" height="40">&nb sp;</td>
</tr>
<tr>
<td colspan="2" align="center"> <input type="submit"
name="Submit" value="Submit">
</td>
</tr>
<tr>
<td><input type="hidden" name="content_i dentifier" value="<?echo
${content_ident ifier}?>"></td>
</tr>
</table>
</form>
<!----END CONTENT AREA --- NO CHANGES BELOW THIS LINE-------->
<?php require_once($_ SERVER['DOCUMENT_ROOT'].'/common/includes/
master_footer.p hp'); ?>
=============== =============== =============== =

master_header.p hp 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.sessio n-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.p hp 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...@thepeters onranch.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_se ssion)) {
ob_start();
ob_clean();
session_start() ;
session_registe r("ADMIN_sessio n");
}
?>
=============== =============== ===

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_ident ifier == false){
$content_identi fier = 'parish';}?>
<? $page_title = "Administration "; ?>
<?php require_once($_ SERVER['DOCUMENT_ROOT'].'/common/includes/
master_header.p hp'); ?>
<?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="adminva lidation.php" method="post">
<table height="100%" border="0" width="81%" align="center"
background="/common/bkgrnds/bg100.gif"">
<tr>
<td colspan="2" height="40">&nb sp;</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>Pleas e Login</strong></
td>
</tr>
<tr>
<td colspan="2" height="40">&nb sp;</td>
</tr>
<tr>
<td align="right">U sername&nbsp;</td>
<td><input type="text" name="user_nm" size="8" maxlength="8">
</td>
</tr>
<tr>
<td align="right">P assword&nbsp;</td>
<td><input type="password" name="password" size="10"
maxlength="10">
</td>
</tr>
<tr>
<td colspan="2" height="40">&nb sp;</td>
</tr>
<tr>
<td colspan="2" align="center"> <input type="submit"
name="Submit" value="Submit">
</td>
</tr>
<tr>
<td><input type="hidden" name="content_i dentifier" value="<?echo
${content_ident ifier}?>"></td>
</tr>
</table>
</form>
<!----END CONTENT AREA --- NO CHANGES BELOW THIS LINE-------->
<?php require_once($_ SERVER['DOCUMENT_ROOT'].'/common/includes/
master_footer.p hp'); ?>
=============== =============== =============== =

master_header.p hp 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.sessio n-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.p hp 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_identi fier == 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...@thepeters onranch.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_se ssion)) {
ob_start();
ob_clean();
session_start() ;
session_registe r("ADMIN_sessio n");
}
?>
=============== =============== ===

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_ident ifier == false){
$content_identi fier = 'parish';}?>
<? $page_title = "Administration "; ?>
<?php require_once($_ SERVER['DOCUMENT_ROOT'].'/common/includes/
master_header.p hp'); ?>
<?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="adminva lidation.php" method="post">
<table height="100%" border="0" width="81%" align="center"
background="/common/bkgrnds/bg100.gif"">
<tr>
<td colspan="2" height="40">&nb sp;</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>Pleas e Login</strong></
td>
</tr>
<tr>
<td colspan="2" height="40">&nb sp;</td>
</tr>
<tr>
<td align="right">U sername&nbsp;</td>
<td><input type="text" name="user_nm" size="8" maxlength="8">
</td>
</tr>
<tr>
<td align="right">P assword&nbsp;</td>
<td><input type="password" name="password" size="10"
maxlength="10">
</td>
</tr>
<tr>
<td colspan="2" height="40">&nb sp;</td>
</tr>
<tr>
<td colspan="2" align="center"> <input type="submit"
name="Submit" value="Submit">
</td>
</tr>
<tr>
<td><input type="hidden" name="content_i dentifier" value="<?echo
${content_ident ifier}?>"></td>
</tr>
</table>
</form>
<!----END CONTENT AREA --- NO CHANGES BELOW THIS LINE-------->
<?php require_once($_ SERVER['DOCUMENT_ROOT'].'/common/includes/
master_footer.p hp'); ?>
=============== =============== =============== =

master_header.p hp 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.sessio n-start]:Cannotsendsess ioncachelimiter- 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.p hp 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
8922
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 code... I never see that explicitly called. Is it supposed to be called from the Global.asa file (still not sure what that is...) Is...
1
3254
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 because it keeps on saying that the http headers has already been sent. It looks like it keeps on telling me that the response is complete. So nothing it...
5
1988
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: Cannot modify header information - headers already sent by (output started at /Users/chrobb/Sites/city-directory/controlBar.php:54) in...
2
1371
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 using the header() function. However I get the headers already sent error. So ive had to type in the connection details on the actual page which isnt...
19
7912
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 limiter - headers already sent in /home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandStartSession.php on line 14
0
1218
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 framework 3.0, which is not an option at the moment. I know one can override this with Response.Cache.SetCacheability method, but I don't know of...
3
3063
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 to.
2
17870
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 SimpleXMLElement is used along with a session. What's the fix, if any? Thanks.
0
8195
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8334
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6596
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5707
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5386
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3831
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2340
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1444
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1171
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.