Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 7

JAYABHARATHI V

KEERTHANA DEVI E
KARTHIGA B
COOKIES IN PHP
Cookies are used to store the information of a web page in a
remote browser, so that when the same user comes back to that page,
that information can be retrieved from the browser itself.

Uses of cookie:

 To store session_id – A cookie could store the session_id of the user.This


stored session_id is secured and hence could be used to read session_id on
request to the server.

 To provide better user preference – A cookie could be used to provide a


better user experience based on the preferences set in the cookie file.
 Setting a Cookie
 Accessing a Cookie
 Destroying a Cookie
Setting a Cookie
To set a cookie in PHP, 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);


Parameters: The setcookie() function requires six arguments in general which are:
Name: It is used to set the name of the cookie.
Value: It is used to set the value of the cookie.
Expire: It is used to set the expiry timestamp of the cookie after which the cookie
can’t be accessed.
Path: It is used to specify the path on the server for which the cookie will be
available.
Domain: It is used to specify the domain for which the cookie is available.
Security: It is used to indicate that the cookie should be sent only if a secure
HTTPS connection exists.

You might also like