Re: setcookie problem: Cannot add header information - headers already sent by
| From: | qartis | Date: | Thu, 14 Mar 2002 00:14:06 +0000 |
| Subject: | Re: setcookie problem: Cannot add header information - headers already sent by | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-88408@lists.php.net to get a copy of this message | ||
I don't think you can have an empty line (even in the php) before cookies
are set
"Frank Ramsay" <fjr@marsdome.myip.org> wrote in message
news:20020313131704.54499.qmail@pb1.pair.com...
> 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 = "webamster@example.com";
> > $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!
>