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().
Asked
Active
Viewed 643 times
-3
-
1http://php.net/manual/en/function.setcookie.php – Muhammad Sep 03 '13 at 04:39
-
1What are you asking? What have you tried ? Codes please. – Raptor Sep 03 '13 at 04:39
-
Just a heads up, questions need to show research effort, or you'll get mad downvotes and lose asking privileges. – Sterling Archer Sep 03 '13 at 04:44
-
@ShivanRaptor I have tried to set cookie in chrome using setcookie but it is not working. – user2277147 Sep 03 '13 at 04:49
2 Answers
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