0

I am trying to set the secure cookie into localhost and it doesn't work for me. My code is below :

<?php    
setcookie("TestCookie", "value1hostonly", time(), "/", "localhost.com", 0, true);
setcookie("TestCookie2", "value2subdom", time(), "/", "localhost", 0, true);

echo @$_COOKIE["TestCookie"];  
echo @$_COOKIE["TestCookie2"];  
?>

Output always show blank . Please guide me.

Dileep Kheni
  • 882
  • 1
  • 7
  • 29

2 Answers2

0

Your expiration time is set to now.

Change time() to time() + 500 or however many seconds until cookie expires.

John McMahon
  • 1,605
  • 1
  • 16
  • 21
  • domain localhost is also a problem: http://stackoverflow.com/questions/1134290/cookies-on-localhost-with-explicit-domain – John McMahon Jan 30 '14 at 05:18
0

Secure cookie not work on localhost . need to test it on server and Change time() to time() + 500 or however many seconds until cookie expires .

Dileep Kheni
  • 882
  • 1
  • 7
  • 29