cookies help

by 6 replies
7
Hi i am trying to make cookie using this code

$cookiename = "abcd";
$cookie_value = "12345";
$expire_time = time()+60*60*24*30;
setcookie("$cookiename", "$cookie_value", "$expire_time");

but my code is not working is there any error ? please tell me
#programming #cookies
  • Make sure that you are doing this on the very first line of output, i.e., before any other HTML is output. Cookies need to be set in the header lines.

    Also not sure why you are surrounding the variables with quotes in the setcookie(); they're not needed.
  • Can you explain in more details what exactly is not working? Are you not able to read the cookie ?
    • [1] reply
    • mean's cookie is not creating, i cannot see cookie in my browser, this code is working fine in my localhost but not in hosting

      When i try to create cookie like this
      setcookie("abc", "123", time()+60*60*24*30);

      Code is working but it's not working with any variables.
      • [1] reply

Next Topics on Trending Feed