A cookie is often used to identify a user. It is a small amount of information that sent by a server to a browser and after that sent back to the browser.
The below is the syntax of cookie:
setcookie(name, value, expire, path, domain, secure, httponly);
name: name of the cookie.
value: value of the cookie stored in clients computer.
expire: expiry date in unix timestamp format. After this time the cookie will become inaccessible.
Path: server path for which the cookie will be available.
Domain: to which domain the cooki is vailble.
Secure: If set to true the cookie is available to secure connection.
Httponly: If set true the cookie is available over http protocol only.
Uses of cookie:
2. User tracking.
3. Maintaining user preferences, shopping cart etc.
Types of cookie:
There are 2 types of cookie:
1. Session cookie
2. Persistent cookie
Session cookie: It is one of the type of cookie, it is also called temprory cookie or non-persistent cookie. It is stored only on the browser memory.When we closed the browser the cookie will be erased.It can not be used for long term tracking information.
Persistent cookie: It is another type of cookie, that is stored in a file on the browsers computer. It can be track long term information. In case, of security it is less secure as compared to session cookie because in this users can easily open the files, see the cookie or changes the values easily.