You cant set cookies after the page has outputed anything.
And some times the page will be called when there isnt anything posted, or no cookies, so you have to check to see if there set
So use this
code:
<?php
//cookies instellen
If($_POST){ //check to see if anything has been posted to the page
setcookie ("Naam", $_POST["naam"], time()+86400); /* onthoud naam voor 24 uur*/
setcookie ("Ipadres", $_SERVER["REMOTE_ADDR"], time()+86400); /*onthoud ip voor 24 uur */
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Cookie Test</title>
</head>
<body>
<form action="cookietest.php" method="post">
<input type="text" name="naam" value="<?php IF(isset($_COOKIE["Naam"])) echo $_COOKIE["Naam"] ?>">
<input type="submit" value="Cookie Instellen" name="Submit">
</form>
<?php
if(isset($_COOKIE["Naam"]) AND isset($_COOKIE["Ipadres"])){ //Check to see if the cookies are set
//dingen naar de pagina printen
print "Als je binnen 24 uur op deze pagina terugkomt, weet het script je naam nog en je ipadres";
print "<br>" . "Naam: " . $_COOKIE["Naam"] . "<br>" . "Ip-adres: " . $_COOKIE["Ipadres"];
}
?>
</body>
</html>
hope it makes sense
700th post