How can we set and destroy the cookie in php?



How can we set and destroy the cookie in php?..

Answer / Hitendra Kumar Trivedi

To set a cookie in PHP:nn```phpnsetcookie("cookie_name", "cookie_value", time() + (86400 * 30), "/" );n```nNote that the fourth parameter sets the path for which the cookie is valid. To destroy a cookie, set its expiration to an earlier date:nn```phpnssetcookie("cookie_name", "", time() - (86400 * 30));n```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More PHP Interview Questions

what is the current salary package in India for a PHP & MySQL programmer who has 3 years experience

127 Answers   ABC, BLG Logistics, Google, HCL, IBM, Infosys, People Group, PHP, Torque Infotech, V Angelz Technologies, Yahoo,


Explain what is the difference between session and cookie?

1 Answers  


How does the identity operator === compare two values?

1 Answers  


"mysql_fetch_row — Get a result row as an enumerated array",this sentence comes from the PHP offical manual.However ,i can not understand the words "enumerated array".I need some help.Thanks a lot to everyone that reply.

1 Answers  


What is the role of php?

1 Answers  


1.Where are the cookies storing ? 2.What is the drawback of using cookies ? 3. If two site is having same cookie name and different values what will be the output if we echo the cookie name from those sites ? How can we solve this issue (How can we specify the domain name)?

8 Answers   TCS,


what is benefit of magento?

1 Answers  


Is it difficult to learn php?

1 Answers  


Is php 7.0 stable?

1 Answers  


How can you insert javascript in php code?

13 Answers   TCS,


How can I retrieve values from one database server and store them in other database server using PHP?

2 Answers   DRC Systems, Photon,


What is the use of mysql_real_escape_string in php?

1 Answers  


Categories