Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

php cookie setting


ghost's Avatar
0 0

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.

ghost's Avatar
0 0

Try using single quotes

<html>

<head>

<title>cookie test(cookie Test)</title>

<?php


setcookie('mission', $yes, time()+2592000);
echo "cookies should be set!";

?>
</head>
</html>

ghost's Avatar
0 0

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>

ghost's Avatar
0 0

That's because the '<html>' sent the headers, you have to set all cookies before any content is displayed


$ch = curl_init();

$ip=&quot;70.176.49.197&quot;;

$username=&quot;knutrainer&quot;;

$mission=&quot;yes&quot;;

$url=&quot;http://www.enigmagroup.org/missions/programming/1/&quot;;
if( ($mission != null))
{
setcookie(&quot;mission&quot;, $mission, time()+2592000); // line 16

// line 17 is below
header(&quot;Location:http://www.enigmagroup.org/missions/programming/1/&quot;;
exit();
}
curl_setopt($ch, curlopt_url, $url);

curl_setopt($ch, CURLOPT_POSTFIELDS, $ip&username&mission);

?&gt;
&lt;html&gt;

&lt;/html&gt;```

ghost's Avatar
0 0

ah maybe that is why i love hbh. keep up the good work!.com wasn't let me set cookies!damn i wish i would have know that lol thanks Jake