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,445
  • 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,591
  • 3
  • 40
  • 46
  • 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 Foobar
  • 11,092
  • 15
  • 56
  • 89
0

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

Arjan
  • 9,784
  • 1
  • 31
  • 41
0

I tested this code, and worked correctly !

<?PHP
setcookie( 'Test' , 'Test' );
echo $_COOKIE['Test'];
?>
DJafari
  • 12,955
  • 8
  • 43
  • 65