Name − This sets the name of the cookie and is stored in an environment variable called HTTP_COOKIE_VARS. This variable is used while accessing cookies.
Value − This sets the value of the named variable and is the content that you actually want to store.
Expiry − This specify a future time in seconds since 00:00:00 GMT on 1st Jan 1970. After this time cookie will become inaccessible. If this parameter is not set then cookie will automatically expire when the Web Browser is closed.
Path − This specifies the directories for which the cookie is valid. A single forward slash character permits the cookie to be valid for all directories.
Domain − This can be used to specify the domain name in very large domains and must contain at least two periods to be valid. All cookies are only valid for the host and domain which created them.
Security − This can be set to 1 to specify that the cookie should only be sent by secure transmission using HTTPS otherwise set to 0 which mean cookie can be sent by regular HTTP.
Following example will create two cookies name and age these cookies will be expired after one hour.
setcookie($cookie_name,$cookie_value,time()+(86400*30),"/");// 86400 = 1 day
echo"Cookie named '".$cookie_name."' is not set!";
echo"Cookie '".$cookie_name."' is set!<br>";
echo"Value is: ".$_COOKIE[$cookie_name];
Note: The setcookie() function must appear BEFORE the <html> tag.
This will produce the following result –
Modify a Cookie Value
To modify a cookie, just set (again) the cookie using the setcookie() function:
Vinay Bobade (Digital Technology Hub) is an excited individual who is enthusiastic for his work. He is anxious to investigate new things other than composing online journals which contain supportive data with respect to IT arrangements and programming administrations. Aside from composing, he is inquiring about on Computerized Innovation industry arrangements