-3

In how many ways you can set a cookie in php. How to set using header(). I have tried to set cookie in chrome using setcookie but it is not working. Want to know how to set using header().

user2277147
  • 163
  • 1
  • 2
  • 9

2 Answers2

0

if you use header('Set-Cookie: ...'); any other cookie that was set using setcookie will not be sent.

DevZer0
  • 13,433
  • 7
  • 27
  • 51
0

try this

setcookie('cookie_name', 'value', 'time');
echo $_COOKIE['cookie_name'];

This is simplest way to set the cookie in php you don't need any configruation for setcookie function. The third argument is optional, you can set time if you want. Header is also a function which is usally use for redirect the page or for set the MIME type. for example

header('location: index.php');
user2727841
  • 715
  • 6
  • 21