I am trying to add a cookie with the following code but i keep getting these errors can someone help me please thanks in advance🙂

<?php
$POST['username'] = stripslashes($POST['username']);
$hour = time() + 3600;
setcookie(ID_my_site,$POST['username'],$hour);
setcookie(Key_my_site,$
POST['pass'],$hour);
//then redirect them to the members area
echo "<script>document.location.href='members.php'</script>";
echo "<script>'Content-type: application/octet-stream'</script>";
?>

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\cookie.php:5) in C:\xampp\htdocs\cookie.php on line 8

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\cookie.php:5) in C:\xampp\htdocs\cookie.php on line 9

    Put both those cookie names within quotes 'ID_my_site'
    It is one string, compare with:
    $str = 'this is a string'

    setcookie('ID_my_site', $_POST['username'], $hour);
    setcookie('Key_my_site', $_POST['pass'], $hour); 

      Check that there is nothing on line 5 before the <?php (spaces, tabs, byte-order marks, etc.)

        put cookie names in quotes no change

        checked for spaces, etc. on line 5 before <?php or before ?> no change

          The error message you first posted states that you're outputting something on line 5 of the script, and that the first setcookie() call is on line 8.

          If you still can't see where the output is, rename the script to have a ".txt" extension and attach it to your next post, that way we can examine the file itself.

            bradgrafelman wrote:

            The error message you first posted states that you're outputting something on line 5 of the script, and that the first setcookie() call is on line 8.

            Which raises the question: what's in the other three lines? If it's not between <?php ... ?> then it's output.

              This is output:

              <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
              <html xmlns="http://www.w3.org/1999/xhtml">
              <head>
              </head>
              <body>

                removed above php code and it all works thanks all

                  The above code wasn't PHP code at all; it was HTML markup, hence why it was output.

                    Write a Reply...