setcookie()


 

setcookie()

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

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

setcookie()

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.

Syntax
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.

Example:

?php
# 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);
?>

Ads