php cookie setting
I am trying to figure out a problem. I dont understand why my code wont set a cookie. Been working on this for 2 hours now and wanted to know if it was me or what.
<head>
<title>cookie test(cookie Test)</title>
<?php
setcookie("mission", $yes, time()+2592000);
echo("cookies should be set!");
?>
</head>
</html>```
Any help even if its highly critical is appreciated.
Here is my new code but I am having problems still with the cookies. Here is the error message.
Warning: Cannot modify header information - headers already sent by (output started at /home/shreves/public_html/enigma_challenge.php:3) in /home/shreves/public_html/enigma_challenge.php on line 16
Warning: Cannot modify header information - headers already sent by (output started at /home/shreves/public_html/enigma_challenge.php:3) in /home/shreves/public_html/enigma_challenge.php on line 17
<?php
$ch = curl_init();
$ip="70.176.49.197";
$username="knutrainer";
$mission="yes";
$url="http://www.enigmagroup.org/missions/programming/1/";
if( ($mission != null))
{
setcookie("mission", $mission, time()+2592000); // line 16
// line 17 is below
header("Location:http://www.enigmagroup.org/missions/programming/1/");
exit();
}
curl_setopt($ch, curlopt_url, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $ip&username&mission);
?>
</html>
That's because the '<html>' sent the headers, you have to set all cookies before any content is displayed
$ch = curl_init();
$ip="70.176.49.197";
$username="knutrainer";
$mission="yes";
$url="http://www.enigmagroup.org/missions/programming/1/";
if( ($mission != null))
{
setcookie("mission", $mission, time()+2592000); // line 16
// line 17 is below
header("Location:http://www.enigmagroup.org/missions/programming/1/";
exit();
}
curl_setopt($ch, curlopt_url, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $ip&username&mission);
?>
<html>
</html>```