Jump to content

setcookie won't set


mrogge

Recommended Posts

Hi,

 

I'm working on a mac with MAMP, phpMyadmin. on localhost, also the mysql server is on my localhost.

 

I've tested in either Safari and Firefox.

 

I'm trying to set my cookie, and it doesn't work, and pulling my hair out. I'm trying out following script which should work, but it doesn't and it's driving me mad. I wanna check the cookie for when a person is or isn't logged in, so that i can show additional data on the .php page

<html>

<body>

<?php

$value = "my cookie value";

 

// send a cookie that expires in 24 hours

setcookie("TestCookie",$value, time()+3600*24);

 

 

// Print individual cookies

echo $_COOKIE["TestCookie"];

 

// Print all cookies

print_r($_COOKIE);

?>

 

</body>

</html>

 

 

Link to comment
https://forums.phpfreaks.com/topic/233370-setcookie-wont-set/
Share on other sites

Look at the error(s) it generates

 

<?php
error_reporting(-1);
ini_set('display_errors', 1);
?>

<html>
<body>
<?php
   $value = "my cookie value";

// send a cookie that expires in 24 hours
setcookie("TestCookie",$value, time()+3600*24);


// Print individual cookies
echo $_COOKIE["TestCookie"];

// Print all cookies
print_r($_COOKIE);
?>

</body>
</html>

 

Link to comment
https://forums.phpfreaks.com/topic/233370-setcookie-wont-set/#findComment-1200100
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.