He IS setting cookie before sending <HTML> block. Note, that he is storing the beginning of <HTL> block in a HEREDOC, which he prints after setting cookie.
Somewhere, he may be printing a blank line prior to setting cookie...that problem has bitten me more than once, so now I'm on the look-out for it in my code. Bob: after the page bombs-out with error message, do a view source on the displayed web-page -----Original Message----- From: Frank Ramsay [mailto:[EMAIL PROTECTED]] Sent: Wednesday, March 13, 2002 7:17 AM To: [EMAIL PROTECTED] Subject: [PHP] Re: setcookie problem: Cannot add header information - headers already sent by Cookies have to be set before the <HTML> block begins. -fjr Bob wrote: > here is the example: > > <?php > // Beginning php > > // Saving the page header in the variable $head. > $head = <<<ENDH > <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> > <html> > <head> > <title>Feedback form</title> > </head> > > <body bgcolor="white"> > <h1 align=center>Feedback form</h1> > ENDH; > // End of page header > > // Saving the page footer in the variable $tail. > $tail = <<<ENDT > <hr> > </body> > </html> > ENDT; > // End of page footer > > // Set up variables that will be saved in the cookies > // Define unique cookie prefix > $ID = "My_ID"; > // Cookie lifetime in seconds (in this example, three days) > $cookie_life = 60; > // Name of cookie that holds the user's name > $n_name = $ID . "_Name"; > // Name of cookie that holds the user's email > $n_email = $ID . "_Email"; > // Name of cookie that holds the user's last login > $n_last = $ID . "_Last"; > > // These lines print the form with user input and mails to the > webmaster. > if( isset($sfeedback)) { > Setcookie($n_last,Date("H:i d/m/Y"),time()+$cookie_life); > print $head; > ?> > Thanks for your feedback, <?php echo $name ?>. Here is what you > said:<br> > Name: <?php echo $name ?><br> > Email: <?php echo $email ?><br> > Feedback: <?php echo $feedback ?><br> > <?php > // Mails the feedback to the webmaster. > $subject = "Feedback from your site"; > $sendto = "[EMAIL PROTECTED]"; > $header = "From: $email"; > mail($sendto, $subject, $feedback, $header); > print "Thank you. Your comments have been sent to the > webmaster\n"; > // Print end and leave > print $tail; > exit(); > } > > // This loop treats users who have not been to the site before. > if(!$$n_last) { > if( ! isset($name)) { // if no name - display the form > echo $head; > ?> > Welcome to our system! Please fill in the following information: > <!-- $PHP_SELF is the PHP way of referring to the current page --> > <form action="<?php echo $PHP_SELF ?>" method="POST"> > Name: <input type="text" name="name"><br> > Email: <input type="text" name="email"><br> > <!-- Submit button --> > <input type=submit value="Submit"></form> > <?php > echo $tail; > exit; > } else { > // Set cookies and continue > Setcookie($n_name,$name,time()+$cookie_life); > Setcookie($n_email,$email,time()+$cookie_life); > $$n_name = $name; > $$n_email = $email; > } > } > > // This loop treats repeat users. > Setcookie($n_last,Date("H:i d/m/Y"),time()+$cookie_life); > echo $head; > ?> > Welcome back to our system, <?php echo $$n_name ?>. > <?php > // Have previous login > if($$n_last) > echo "Your last login was on " . $$n_last . "."; > > // User fills in feedback form > ?> > <form action="<?php echo $PHP_SELF ?>" method="POST"> > Name: <input type="text" name="name" value="<?php echo $$n_name > ?>"><br> > Email: <input type="text" name="email" value="<?php echo $$n_email > ?>"><br> > Feedback:<br> > <textarea name="feedback" wrap=virtual cols=40 rows=5> > </textarea> > <br> > <!-- Submit button --> > <input type=submit value="Submit" name="sfeedback"> > </form> > <?php echo $tail ?> > > > Warning: Cannot add header information - headers already sent by > (output started at C:\WebShare\wwwroot\last\cookie.php:59) in > C:\WebShare\wwwroot\last\cookie.php on line 75 > > Warning: Cannot add header information - headers already sent by > (output started at C:\WebShare\wwwroot\last\cookie.php:59) in > C:\WebShare\wwwroot\last\cookie.php on line 76 > > Warning: Cannot add header information - headers already sent by > (output started at C:\WebShare\wwwroot\last\cookie.php:59) in > C:\WebShare\wwwroot\last\cookie.php on line 83 > > what' wrong? > thanks! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php