Cookie in PHP - Web Development

Cookie in PHP

A cookie is very essential part of any programming language. PHP setcookie() function is used to set cookie with HTTP response. Once the cookie is set, you can access it by $_COOKIE superglobal variable.

Cookie is created at server side and saved to client browser. Each time when client sends request to the server, cookie is embedded with request. Such way, cookie can be received at the server side.

  1. setcookie(“CookieName”, “CookieValue”);/* defining name and value only*/  
  2. setcookie(“CookieName”, “CookieValue”, time()+1*60*60);//using expiry in 1 hour(1*60*60 seconds or 3600 seconds)  
  3. setcookie(“CookieName”, “CookieValue”, time()+1*60*60, “/mypath/”, “”, 1);  

Output :

Sorry, Your cookie is not found

Leave a Reply

Your email address will not be published. Required fields are marked *