Cannot modify header information - headers already sent by

i am getting this error when running my script:

Warning: Cannot modify header information - headers already sent by (output started at D:Program Fileswampwwwtrainingindex.php:4) in D:Program Fileswampwwwtrainingindex.php on line 11

here is the code:

[code]<?php
if (!isset($_COOKIE[‘mycookiename’]))
{
echo “No cookie present, making cookie”;

    //Get the current time and make the cookie
    $time = time();
    $username = "anton";
    $password = "pass";
    $cookie_data = $username.'-'.$password;
    if (setcookie ("mycookiename",$cookie_data, $time+3600)==TRUE)
    {}
    else
    {
        echo "Your computer does not support cookies.";
        exit();
    }
 }
 
 //Use cookie and Extract the cookie data (Username and Password)
 $cookie_info = explode('-', $_COOKIE['mycookiename']);
 $namecookie = $cookie_info[0];
 $passcookie = $cookie_info[1];
 
 echo "Username: $namecookie<br>Password: $passcookie";

?>[/code]

A simple visit to the PHP manual would have easily gotten you the answer to this one.

setcookie() defines a cookie to be sent along with the rest of the HTTP headers. Like other headers, cookies must be sent before any output from your script (this is a protocol restriction). This requires that you place calls to this function prior to any output, including and tags as well as any whitespace.
Sponsor our Newsletter | Privacy Policy | Terms of Service