Jump to content

Setcookie gives me "cannot modify header information", setcookie before anything


Recommended Posts

Hi everyone. Im a newbie here so please be gentle.  :)

 

I`ve had difficulties to solve my problem for a long time now. I receive the error:

 

Warning: Cannot modify header information - headers already sent by (output started at /home/fotonavi/public_html/side/kameraer.php:36) in /home/fotonavi/public_html/side/kameraer.php on line 20

 

Warning: Cannot modify header information - headers already sent by (output started at /home/fotonavi/public_html/side/kameraer.php:36) in /home/fotonavi/public_html/side/kameraer.php on line 20

 

Warning: Cannot modify header information - headers already sent by (output started at /home/fotonavi/public_html/side/kameraer.php:36) in /home/fotonavi/public_html/side/kameraer.php on line 20

 

Warning: Cannot modify header information - headers already sent by (output started at /home/fotonavi/public_html/side/kameraer.php:36) in /home/fotonavi/public_html/side/kameraer.php on line 20

 

Warning: Cannot modify header information - headers already sent by (output started at /home/fotonavi/public_html/side/kameraer.php:36) in /home/fotonavi/public_html/side/kameraer.php on line 20

 

Warning: Cannot modify header information - headers already sent by (output started at /home/fotonavi/public_html/side/kameraer.php:36) in /home/fotonavi/public_html/side/kameraer.php on line 20

 

If someone goes at my website for their first time, this error shows up. If you push F5 (reload the page), then it disappears.

 

I know that setcookie must be set before any htm&header is outputed. And it is. My code is given below. Line 20 is setcookie

 

<?php session_start();
GetCartId();
function GetCartId()
{
// This function will generate an encrypted string and
// will set it as a cookie using set_cookie. This will
// also be used as the cookieId field in the cart table

if(isset($_COOKIE["cartId"]))
{

return $_COOKIE["cartId"];
}
else
{

// There is no cookie set. We will set the cookie
// and return the value of the users session ID

setcookie("cartId", session_id(), time() + ((3600 * 24) * 30));


return session_id();

}
}

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- Created on: 10/1/2006 -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Language" content="English" />
<meta name="author" content="AI" />
<meta name="Robots" content="index,follow" />
<meta name="description" content="describe the page" />
<meta name="keywords" content="insert your keywords here seperated by comma" />
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="../css/style.css" />
<title>Fotonavid</title>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
</head>
<body>
<div id="main">
<div id="top">
<div id="topmenu"><?php include "../include/menu/topmenu.html";   ?></div>
</div>
<div id="header">
<div id="sitename"><br />
    </div>
</div>

  <div class="container"><br />
    <div class="header"> 
      <!-- you can insert javascript or other date script within above span -->
    </div>
    <div class="menu">
<div id="item"> 
       <p><?php include "../include/menu/sidemenu.html";   ?>
        <p> </p>
      </div></div>
    <div class="content">
         <?php include "../include/php_cart/db.php"; ?>
        <br />
        <?php include "../include/php_cart/cart.php";?> <br>
      <p>Foreløpig er Nikon kameraer listet. Andre modeller kommer snart. 
        Hvis noe ikke står på listen så send meg mail for pris.<br />
        <?php include "../produkter/speilrefleksnikon.php";   ?>
      <p>
	<?php include "../produkter/speilreflekscanon.php";   ?>


      </p>
      <table width="85%" border="0">
        <tr> 
          
        </tr>
      </table>
      <h2><font size="+1"></font></h2>
    </div>

    <div class="footer"> © Copyright 2008 Design by : Navid </div>
</div>
</div>
</body>
</html>

 

Please help me with this one. I just dont get it and i have searched on the internet without finding any answers.

 

Thanks a lot guys  :)

 

 

 

To explain what is going on, you are trying to set a cookie after output has been sent to the browser.

 

Thanks for answering. With output, do you mean ANY code which is above setcookie? So setcookie must be on very top? How can i do this when i at the same time have to have this in a function like i have?

 

in cart.php (which is included below in my code i gave above) i use GetCartId() for retrieveing the sessionid. Some part of the code where i use the function GetCartId is shown below. How to fix this then?

 

cart.php

 

function RemoveItem($itemId)
{
	// Uses an SQL delete statement to remove an item from
	// the users cart

	global $dbServer, $dbUser, $dbPass, $dbName;

	// Get a connection to the database
	$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);

	mysql_query("delete from cart where cookieId = '" . GetCartId() . "' and itemId = $itemId");	
}

 

 

Thanks

 

To explain what is going on, you are trying to set a cookie after output has been sent to the browser.

 

Thanks for answering. With output, do you mean ANY code which is above setcookie? So setcookie must be on very top? How can i do this when i at the same time have to have this in a function like i have?

 

in cart.php (which is included below in my code i gave above) i use GetCartId() for retrieveing the sessionid. Some part of the code where i use the function GetCartId is shown below. How to fix this then?

 

cart.php

 

function RemoveItem($itemId)
{
	// Uses an SQL delete statement to remove an item from
	// the users cart

	global $dbServer, $dbUser, $dbPass, $dbName;

	// Get a connection to the database
	$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);

	mysql_query("delete from cart where cookieId = '" . GetCartId() . "' and itemId = $itemId");	
}

 

 

Thanks

 

 

No one can help?

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.