...

View Full Version : error:...cannot send session cache limiter... headers already sent by php...



srihari3d
09-14-2009, 04:47 PM
error:...cannot send session cache limiter...
headers already sent by php....can any one give me the solution?..........when ever login with username & password...the session is not stored in the first time....but the next time login the session is stored with the username....what is the prblm?.....i m sending code also......

<?ob_start();
session_start();?>
<?php
$_SESSION['susername']=$_POST["username"];
if($_SESSION['susername']=="")
$ssusername= $_SESSION['profileusername'];
else
$ssusername= $_SESSION['susername'];
Header("Location: ./profile.php");
if($ssusername=="")
require "serverbusy.html";
//session_register("ssusername");
?>
please give me the reply.........
i m waiting for that............

SKDevelopment
09-14-2009, 05:02 PM
I think you have a space before "<?ob_start();". In this case the server has already started output of the HTTP document. Which means the HTTP headers are already sent.

Please check that there in no output before "<?ob_start();" in your script. Absolutely nothing - even spaces. If the output has started, it could be a little bit late to turn on buffering ... Headers have been sent already.

srihari3d
09-15-2009, 10:03 AM
there is no spaces before "<?ob_start();". .....the same code in local machines worked successfully.....i uploaded code into internet.......it will give the error....what is the reason....can u give me any other option......plz give me the reply........

SKDevelopment
09-15-2009, 10:39 AM
This code


<?ob_start();
session_start();?>
<?php
$_SESSION['susername']=$_POST["username"];
if($_SESSION['susername']=="")
$ssusername= $_SESSION['profileusername'];
else
$ssusername= $_SESSION['susername'];
Header("Location: ./profile.php");
if($ssusername=="")
require "serverbusy.html";
//session_register("ssusername");
?>

works for me without any problems andd does not produce any errors. I tried it both under Windows and under Linux.

Have you posted all the errors you are getting from the script ? Only "can not send session cache limiter. Headers already sent" ? Maybe some other error has been shown before this ? In this case that error would be the the output about which the server complained ... I am sorry for asking questions, but without this information it is really difficult to help ...

This "Headers already sent" error could mean only 1 thing - some output has started before you used a function sending HTTP headers (in your case session_start()).

The line "<?ob_start();" is really the first line in the script file with nothing before it ?

Off-topic: I would use "<?php ob_start();" instead of "<?ob_start();". Using short tags ("<?" instead of "<?php") is considered bad programming practice. If once you move your code to a server with short tags off, you would get all your PHP code in the browser as plain text for anyone to view. Also I do not see why you could possibly need ob_start() in this small script at all ...

srihari3d
09-15-2009, 10:55 AM
sir,
in my server the code is working perfectly.....but i m using bravenet hosting server....it will give the error....i m sending error message:
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /misc/16/000/211/946/9/user/web/dianimations.com/login.php:8) in /misc/16/000/211/946/9/user/web/dianimations.com/index1.php on line 2

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /misc/16/000/211/946/9/user/web/dianimations.com/login.php:8) in /misc/16/000/211/946/9/user/web/dianimations.com/index1.php on line 2

Warning: Cannot modify header information - headers already sent by (output started at /misc/16/000/211/946/9/user/web/dianimations.com/login.php:8) in /misc/16/000/211/946/9/user/web/dianimations.com/index1.php on line 75

when ever login with username the session is empty....if u login second time it will take session as username.....i want: when ever login with username the session is stored with ssusername.....
if u want check my website:www.dianimations.com
username:srihari3d
password:devineni

i am waiting for the answer.....plz give me....

SKDevelopment
09-15-2009, 11:46 AM
I hope your login and password are not sensitive information. You have published them at a public forum. If it is sensitive information, please change these login and password anywhere you ever used them.

Could you comment out ob_start(); and see which the error would be produced in this case ? Could you try the following:


<?php
session_start();

$_SESSION['susername']=$_POST["username"];
if($_SESSION['susername']=="")
$ssusername= $_SESSION['profileusername'];
else
$ssusername= $_SESSION['susername'];

session_write_close();
header("Location: ./profile.php");
exit;

//if($ssusername=="")
//require "serverbusy.html";

//session_register("ssusername");
?>

I commented 2 lines below because they are after the redirect. the line
header("Location: ./profile.php");
never was in the else-block (you do not have curly brackets so only the 1st statement after else belongs to the else-block). So no matter what you include after redirect, normally the user would not see that anyway ... Please uncomment the lines and remove exit; if you think you could need them.

srihari3d
09-15-2009, 12:46 PM
i got this error....Cannot send session cookie - headers already sent by ......
same problem.........the code all are correct.....plz give me the answer...

djm0219
09-15-2009, 01:19 PM
Are you showing us index1.php or login.php? The message clearly states that login.php has already sent headers of some sort so, if you're showing us index1.php, the session_start will result in the error.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum