Can someone please help me I have made an example, of an cookies I have added a value 45 but i have created another page that displays. This prob is when i run the code that has the value 45 its suppose to give me a blank page byut i get this error on my browser

"Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\lesson\cookies\cookies.php:6) in C:\xampp\htdocs\lesson\cookies\cookies.php on line 11"

this is the code i put the cookie its suppose to just give a blank page but the value is stored in the cookie

<?php
	setcookie('test',45, time()+(60*60*24+7));
?>

This is pretty common for programmers new to php. We'll need to see more code. Are you using echo or print before the header? Here's an article about the error.

Also any characters (even null or whitespace) before the opening <?php tag can also cause this error so make sure that your <?php starts at the very first line and column of your script.

In particular check line 6 (cookies.php:6) to see what you have that outputs there.

Can someone please help me I have made an example, of an cookies I have added a value 45 but i have created another page that displays. This prob is when i run the code that has the value 45 its suppose to give me a blank page byut i get this error on my browser

"Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\lesson\cookies\cookies.php:6) in C:\xampp\htdocs\lesson\cookies\cookies.php on line 11"

this is the code i put the cookie its suppose to just give a blank page but the value is stored in the cookie

<?php
	setcookie('test',45, time()+(60*60*24+7));
?>

Your PHP code for your cookie needs to be set before the <html> like this:

<?php
setcookie('test',45, time()+(60*60*24+7));
?>
<html>
<head>

<title>Your Title</title>
</head>
<body>

</body>
</html>

Also any characters (even null or whitespace) before the opening <?php tag can also cause this error so make sure that your <?php starts at the very first line and column of your script.

Also any characters (even null or whitespace) before the opening <?php tag can also cause this error so make sure that your <?php starts at the very first line and column of your script. ??

Why ?? The following example is taken from lyna.com . Is any thing wrong ? The error is same for this example .

<html>
    <head>
        <title>Cookies</title>
    </head>
    <body>

        <?php // Setting a cookie

            // setcookie(name, value, expiration);
            setcookie('test', 45, time()+(60*60*24*7));
        ?>

    </body>
</html>
This article has been dead for over six months. Start a new discussion instead.