Announcement

Collapse
No announcement yet.

Oops, php3_SetCookie called after header has been sent

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Tim Mousel
    replied
    Hi,

    You were right! I removed a space at the top of the script and now all is working well.

    Thank you very much,

    Tim

    Leave a comment:


  • Skut
    replied
    Hi,
    I'm guessing the problem is that you have inserted a space or spaces in the code where there should not be any...
    most likely at the very start before <?
    hope this helps,

    Conor
    Attached Files

    Leave a comment:


  • Oops, php3_SetCookie called after header has been sent

    Hi,
    Here is my page: http://worldslargestmall.cc/personalize/signup.php

    I modified this script: http://www.thescripts.com/php/tutori...ize/print.html and am receiving the following error when I try to submit the register form:

    Warning: Oops, php3_SetCookie called after header has been sent in /home/public_html/personalize/register.php3 on line 20

    Warning: Oops, php3_SetCookie called after header has been sent in /home/public_html/personalize/register.php3 on line 21

    Here is the script:

    <?php

    mysql_connect("localhost", "us11", "test");
    mysql_select_db("db11");


    if ($Password == $Password2) {
    $user = mysql_query("SELECT * FROM personalize WHERE (Name='$Name')");
    if (mysql_num_rows($user) > 0) {
    include ("prepend.inc");
    CommonHeader("User Name Taken !");
    ?>
    <P><center>We are sorry to inform you that the User Name <?php echo $Name ?> is already taken. Please hit the back button in your browser and try again. </center>
    <?php
    CommonFooter();
    }
    else {
    $user = mysql_query("INSERT INTO personalize VALUES ('$Name','$Password','$News1','$News2','$Weather','$News3')");
    setcookie("site_user", $Name, time() + 31536000, "/");
    setcookie("site_pass", $Password, time() + 31536000, "/");
    include ("prepend.inc");
    CommonHeader("Registration Success!");
    ?>
    <P><center>You have registered.<BR>
    User Name: <?php echo $Name ?>
    <BR>
    Password: <?php echo $Password ?>
    <P>Click <a href="http://worldslargestmall.cc/personalize/">here</a>; to go back to your personalized page.</center>
    <?php
    CommonFooter();
    }
    }
    else {

    ?>
    <?php include "prepend.inc"; ?>
    <? CommonHeader("World's Largest Mall"); ?>
    <P><center>Your Two Passwords Did Not Match. Please hit the back button in your browser and try again. </center>
    <?php
    CommonFooter();
    }
    ?>

    #########
    prepend.inc contains the html for my header and footer.

    Even though the error appears, the info is still saved in the mysql database.

    I know a header isn't supposed to be sent before setting the cookie, but I don't see any way around this...especially if the user enters a bad password or username.

    Is there a better way this could be written?

    Please give a beginner some good tips!!

    Thanks in advance,

    Tim

    Tim Mousel
widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
Working...
X