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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.