How to set and get and delete cookie in PHP?

Posted by Editorial Staff | Updated on

To set a cookie in PHP, use the setcookie() function is used. The setcookie() function needs to be called prior to any output generated by the script otherwise the cookie will not be set. Syntax : setcookie(name, value, expire, path, domain, security);

Syntax:

Example #1 setcookie() send example

Example #2 setcookie() delete example

Example #3 setcookie() and arrays

Output

Further Reading: https://www.php.net/manual/en/function.setcookie.php


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers