Jump to content

Recommended Posts

I have encounter this warning before

 

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home3/store/includes/connection.php:39) in /home3/store/includes/connection.php on line 30

 

Could I use the function ob_start();  before session star() and use it anywhere I want? or do I have to star it before any out any ways?

 

I once used ob _start() function before a header() and it worked. It started the hearder even though there were other outputs before the header() function.

Link to comment
https://forums.phpfreaks.com/topic/189043-a-warning-using-session-start-again/
Share on other sites

<?php header('Content-type: text/html; charset=utf-8');?>
<?php session_start();
function GetCartId()
{
if(isset($_COOKIE["cartId"]))
{
return $_COOKIE["cartId"];
}
else
{
setcookie("cartId", session_id(), time() + ((3600 * 24) * 30)); //line 11
return session_id();
}
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

 

Warning: Cannot modify header information - headers already sent by (output started at /home3/includes/header3.php:24) in /home3/includes/header3.php on line 11

 

It seem that it setcookie function has a problem when it is not started at the top as well. Because the session is at the top and it is not throwing any error but there is a warning for line 11 where the function setcookie() is. But how can I put it at the top wherer the else statment won't have any effect on it?

 

I think ob_start would be of a good use right? where exactly should I use ob_start(); here or how can I take that warning out of the way? Right now it is working but the warning doesn't look too pretty in the screen.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.