COOKIES QUESTION OF PHP

Q.1 How to set cookies?

ANSWER: setcookie(’variable’,'value’,'time’)
;
variable – name of the cookie variable
value – value of the cookie variable
time – expiry time
Example: setcookie(’Test’,$i,time()+3600);

Test – cookie variable name
$i – value of the variable ‘Test’
time()+3600 – denotes that the cookie will expire after an one hour

Q.2 How to reset/destroy a cookie

ANSWER: Reset a cookie by specifying expire time in the past:
Example: setcookie(’Test’,$i,time()-3600); // already expired time

Reset a cookie by specifying its name only
Example: setcookie(’Test’);

Q.3How can we destroy the cookie?

ANSWER: Set the cookie with a past expiration time.

Q.4 What Is a Persistent Cookie?

ANSWER: A persistent cookie is a cookie which is stored in a cookie file permanently on the browser’s computer. By default, cookies

are created as temporary cookies which stored only in the browser’s memory. When the browser is closed, temporary cookies

will be erased. You should decide when to use temporary cookies and when to use persistent cookies based on their

differences:

* Temporary cookies can not be used for tracking long-term information.
* Persistent cookies can be used for tracking long-term information.
* Temporary cookies are safer because no programs other than the browser can access them.
*
* Persistent cookies are less secure because users can open cookie files see the cookie values.