3

What's wrong with this code?

setcookie("password",$wachtwoord,0, "/", ".thedomainname.com");
echo $_COOKIE['password']; //shows nothing

I am attempting to set a cookie and display its value?

dplante
  • 2,417
  • 3
  • 21
  • 27
Jay
  • 51
  • 3
  • 4
    You should not store passwords in cookies. – Arjan Apr 30 '11 at 10:53
  • possible duplicate of [Accessing $_COOKIE immediately after setcookie()](http://stackoverflow.com/questions/3230133/accessing-cookie-immediately-after-setcookie) – outis Mar 25 '12 at 19:57

4 Answers4

3

Are you waiting for the next request before you examine $_COOKIE ?

Lee Kowalkowski
  • 11,411
  • 3
  • 38
  • 45
  • the echo is right after I've set it, but normally the page refreshes and I'm not logged in. When I test it at localhost without the domain setting it works perfectly. So there's something wrong with that part I guess... – Jay Apr 30 '11 at 13:19
3

$_COOKIE[] with that new cookie will be available only with next request

Larry Cinnabar
  • 10,840
  • 15
  • 54
  • 88
0

You can't access the cookie until after you reload the page.

Arjan
  • 9,538
  • 1
  • 30
  • 40
0

I tested this code, and worked correctly !

<?PHP
setcookie( 'Test' , 'Test' );
echo $_COOKIE['Test'];
?>
DJafari
  • 11,418
  • 8
  • 39
  • 61