Share on Google+Share on Google+


In this example you will learn how to create setcookie() in PHP.


setcookie() sends a HTTP cookie - a small file that the server engrafts on the user's computer - to a client. A cookie must be assigned before any other output is sent to the clients. A name of the cookie is automatically assigned to a variable of the same name. It returns True on success or False on  failure.

setcookie(name, value, expire, path, domain); 

Parameter Description

Name is essential for specifying the cookie; Value is also important while 'cookie expire' is optional, if it is specified, the session expires at the defined time.


# setcookie(name, value, expire, path, domain); // is a function for set cookie but path and domain are optional
setcookie("cookie", "brijesh kumar singh", time()+3600);


Posted on: July 31, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.