1,105,386 Community Members

Warning: session_start(): Cannot send session cache limiter - headers already sent

Member Avatar
manish812
Newbie Poster
12 posts since Jun 2006
Reputation Points: 11 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

Whenever i run session in server than it show this problem

Warning: session_start(): Cannot send session cache limiter - headers already sent

so pls help me

this is simple login prog when user enter into nxt page it name will show i want to store its name in session

i m giving full code wht i m using if thr is anything wrong pls tell me :sad: :sad: :sad: :sad: :sad: :sad: :sad: :sad: :sad: :sad:

<? @session_start();?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0046)http://acmserver.cs.ucr.edu/~nkumar/vision.htm -->
<HTML>
<HEAD><TITLE>Bankon Us</TITLE>
<META http-equiv=Content-Type content="text/html; charset=utf-8">

<link rel="stylesheet" href="style.css" type="text/css">
<body topmargin="0" leftmargin="0">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<TD align=center>
<table cellpadding="0" cellspacing="0" border=0 width="100%">
<tr><td height="25">&nbsp;</td></tr>
<tr>
<td width="50%" align="right">
<?php
$_SESSION= $_POST;
$_SESSION= $_POST;
$_SESSION=$_POST;
if (($_SESSION == "peter") and ($_SESSION == "gewant") and ($_SESSION == "approvalagent"))
{
//header("Location:admin_page.php");
echo "<meta http-equiv='Refresh' content='0; url=admin_page.php'>";
exit;
}
$f_name= $_POST;
$l_name= $_POST;
$pass= $_POST;
if($_POST != "Login")
{
?>
<table border="0" cellpadding="5" cellspacing="3" width="80%" class="form-noindent">
<tr><td bgColor="#ff9900">
<form method="post" action="<?php $_SERVER?>">
<input type="hidden" name="agent" value="access">
<table border="0" width="100%">
<tr>
<td colspan="3" align="center" class="heading">Sign in with your<br> Account</td>
</tr>
<tr><td>&nbsp;</td></tr>
<tr>
<td>&nbsp;</td>
<td class="textform">First Name&nbsp;:</td>
<td class="forms" valign="top">
<input name="fname" class="cartForm" size=20 type="text"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td class="textform">Last Name&nbsp;:</td>
<input name="lname" class="cartForm" size=10 type="hidden">
<td class="forms" valign="top">
<input name="lname" class="cartForm" size=20 type="text"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td class="textform">Password&nbsp;:</td>
<td class="forms" valign="top">
<input class="cartForm" name="password" size=20 type="password"></td>
</tr>
<tr>
<td valign="top" colspan="3" align="center">&nbsp;&nbsp;
<input type="submit" name="submit" value="Login" class="cartForm" >
</td>
</tr>
<tr><td colspan="3">&nbsp;</td></tr>
<tr>
<td colspan="2" align="center"><div class="leo"><a href="forget.php">Forget Password</a></div></td>
<td align="center"><div class="leo"><a href="order.php">New user click here</a></div></td>
</tr>
</table>
</form>
</td></tr>
</table>
</td>
<td width="50%" align="center"><img src="images/online.jpg"></td>
</tr>
</table>
<br><br>
<?php }
elseif($f_name== "" or $l_name== "" or $pass== "")
{
?>
<table border="0" cellpadding="5" cellspacing="3" width="80%" class="form-noindent">
<tr><td bgcolor="#00CC99">
<form method="post" action="<?php $_SERVER ?>">
<input type="hidden" name="agent" value="access">
<table border="0" width="100%">
<tr>
<td colspan="3" align="center" class="heading">Sign in with your Account</td>
</tr>
<tr><td>&nbsp;</td></tr>
<tr><td colspan="3" align="center" class="heading">Please fill all the fields</td></tr>
<tr><td>&nbsp;</td></tr>
<tr>
<td>&nbsp;</td>
<td class="textform">First Name&nbsp;:</td>
<td class="forms" valign="top">
<input name="fname" class="cartForm" size=20 type="text"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td class="textform">Last Name&nbsp;:</td>
<input name="lname" class="cartForm" size=10 type="hidden">
<td class="forms" valign="top">
<input name="lname" class="cartForm" size=20 type="text"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td class="textform">Password&nbsp;:</td>
<td class="forms" valign="top">
<input class="cartForm" name="password" size=20 type="password"></td>
</tr>
<tr>
<td valign="top" colspan="3" align="center">&nbsp;&nbsp;
<input type="submit" name="submit" value="Login" class="cartForm" >
</td>
</tr>
<tr><td colspan="3">&nbsp;</td></tr>
<tr>
<td colspan="2" align="center"><div class="leo"><a href="forget.php">Forget Password</a></div></td>
<td align="center"><div class="leo"><a href="order.php">New user click here</a></div></td>
</tr>
</table>
</form>
</td></tr>
</table>
</td>
<td width="50%" align="center"><img src="images/login1.jpg" width="300" height="200"></td>
</tr>
</table>
<?php
}
else {
$query = "SELECT * from users WHERE firstname='$f_name' and lastname='$l_name' and password='$pass' ";
$result = mysql_query($query);
for ($i = 0; $i < mysql_num_rows($result); $i++)
{
$id = mysql_result($result, $i, "id");
$fname = mysql_result($result, $i, "firstname");
$lname = mysql_result($result, $i, "lastname");
$pas = mysql_result($result, $i, "password");
if (("$f_name" == "$fname") and ("$l_name" == "$lname") and ("$pass" == "$pas"))
{
$_SESSION = $f_name;
$_SESSION = $l_name;
echo "<meta http-equiv='Refresh' content='0; url=user_page.php'>";
exit;
}//if loop
}//for loop
echo "<meta http-equiv='Refresh' content='0; url=new_user.php'>";
//header("Location:new_user.php");
exit;
}
?>
</td>
</tr>
</table>
</BODY>
</HTML>

Member Avatar
digital-ether
Nearly a Posting Virtuoso
1,264 posts since Sep 2005
Reputation Points: 399 [?]
Q&As Helped to Solve: 102 [?]
Skill Endorsements: 11 [?]
Team Colleague
 
-1
 

Headers already sent refers to HTTP Headers.
The server cannot send any more http headers if the HTTP Content has started sending.
In PHP code, this means you have ouput something to the page with echo or print etc.

PHP will not output any whitespace in between php tags, However, for anything outside php tags, (eg: html) whitespaces, linebreaks are sent as HTTP Content.
Sometimes this your editor may add whitespace also.

To prevent whitespace from being sent before you send all your headers, make sure the <?php is right at the top of the php script, and there are no lines or white space in between.

You can also use output buffering, ob_start() to buffer your PHP output before sending it to HTTP. Then use ob_flush() to send http output when you need.
see: http://www.php.net/manual/en/function.ob-start.php

I noticed you have //header("Location:admin_page.php"); in your page. You can use the output buffering to allow you to send this header even after you have echo and html output in your php.

Member Avatar
maiahost
Newbie Poster
13 posts since May 2006
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
1
 

You have blank lines in your HTML code, remove them and try again.

Member Avatar
Puckdropper
Posting Pro in Training
494 posts since Jul 2004
Reputation Points: 7 [?]
Q&As Helped to Solve: 24 [?]
Skill Endorsements: 0 [?]
 
1
 

Works fine for me. Attached is the code I copied and pasted, so you have at least a file that worked.

My test was done with EasyPHP, with the PHP version upgraded to 5.04.

Attachments someguyscode.php (4.97KB)
Member Avatar
cancer10
Posting Whiz in Training
234 posts since Dec 2004
Reputation Points: 47 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

Pass the header before any HTML tags or else it would show errors

Member Avatar
neeraj93
Newbie Poster
1 post since Sep 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

Use This Php Script at top of the your php page this script start session before dowload include file i hope you will solve this problem.
<URL SNIPPED>

<?php 
if (!isset($_SESSION)) {
  session_start();
}
?>
Member Avatar
Shanti C
Posting Virtuoso
1,675 posts since Jul 2008
Reputation Points: 106 [?]
Q&As Helped to Solve: 165 [?]
Skill Endorsements: 4 [?]
 
0
 

this error will occur at the times of:

1.any space is there before the session_start(); function..Means it sholu be the first line of your application...
2.dont use session_start(); as twice (in your main application and in your included application)

Member Avatar
jeyakannanrd
Newbie Poster
3 posts since Aug 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/leadtwot/public_html/staging/contact_us.php:1) in /home/leadtwot/public_html/staging/contact_us.php on line 1

Member Avatar
tami64
Newbie Poster
7 posts since Jul 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

hey dude
are you sure you dont use include code?
session code must be before include

Member Avatar
storm123
Newbie Poster
11 posts since May 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 2 [?]
Skill Endorsements: 0 [?]
 
0
 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/leadtwot/public_html/staging/contact_us.php:1) in /home/leadtwot/public_html/staging/contact_us.php on line 1

I have this problem too. I tried everything without success.
After long research i found the reason and decision in this place.
I hope that's help you and save your time.

Member Avatar
Ankit_Parmar
Light Poster
47 posts since Jul 2010
Reputation Points: 1 [?]
Q&As Helped to Solve: 8 [?]
Skill Endorsements: 0 [?]
 
0
 

Headers already sent refers to HTTP Headers.
The server cannot send any more http headers if the HTTP Content has started sending.
In PHP code, this means you have ouput something to the page with echo or print etc.

PHP will not output any whitespace in between php tags, However, for anything outside php tags, (eg: html) whitespaces, linebreaks are sent as HTTP Content.
Sometimes this your editor may add whitespace also.

To prevent whitespace from being sent before you send all your headers, make sure the <?php is right at the top of the php script, and there are no lines or white space in between.

You can also use output buffering, ob_start() to buffer your PHP output before sending it to HTTP. Then use ob_flush() to send http output when you need.
see: http://www.php.net/manual/en/function.ob-start.php

I noticed you have //header("Location:admin_page.php"); in your page. You can use the output buffering to allow you to send this header even after you have echo and html output in your php.

Thank You for Solution.....

Member Avatar
rajarajan07
Nearly a Posting Virtuoso
1,448 posts since May 2008
Reputation Points: 123 [?]
Q&As Helped to Solve: 242 [?]
Skill Endorsements: 3 [?]
 
0
 
Member Avatar
martybabes
Newbie Poster
1 post since Jun 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

I had the same problem until went to my file manager and checked what was in my file on the server. there I found garbage added to the start of the file - in my case a dash was added:
sample.php
line 1:-<?php etc.
I get 3 extra chars on my Virtual server, and it happens with 3 ftp clients I have used so far. (I'm using Windows 7 OS).

Member Avatar
abhijits
Newbie Poster
2 posts since Nov 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

thanks to solve my error

Member Avatar
abhijits
Newbie Poster
2 posts since Nov 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

please you continues your good work for other issue

Member Avatar
mahendra1
Newbie Poster
2 posts since Apr 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

session_start() must be at the first line of the page.
Should not contain any spaces before it.

Member Avatar
aksahoo17
Newbie Poster
20 posts since Nov 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

Thanks...a lot to all of u ...its help me a lot..
thanks once again..

Question Answered as of 3 Years Ago by abhijits, aksahoo17, Puckdropper and 12 others
Member Avatar
Manmohit Verma
Newbie Poster
1 post since Sep 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Yeah Thanxxx.. i done it. there are a single space in code..
after half hour strugle i had done. :-)

Member Avatar
xoso888.vn
Newbie Poster
1 post since Nov 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

To solve this problem, you do the following:
Step 1: Download and install nodepad + + latest version.
Step 2: open the php file that you run corrupted by nodepad + +. select tab: encoding -> encoding in UTF-8 without BOM.
Then you run the program is ok.

Member Avatar
edensigauke
Junior Poster in Training
59 posts since Nov 2007
Reputation Points: -8 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

To fix the session_start() problem, change the line in your PHP config file for sessions and change it to maybe C:\PHP\PHPSession after having created the folder of course and restart your server and try checking your page again.

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article