{"id":23,"date":"2008-05-17T03:27:00","date_gmt":"2008-05-17T07:27:00","guid":{"rendered":"http:\/\/www.searchenginegenie.com\/programming-blog\/how-to-use-cookies-in-php\/"},"modified":"2010-07-20T11:16:13","modified_gmt":"2010-07-20T15:16:13","slug":"how-to-use-cookies-in-php","status":"publish","type":"post","link":"https:\/\/www.searchenginegenie.com\/programming-blog\/how-to-use-cookies-in-php\/","title":{"rendered":"How to use cookies in PHP"},"content":{"rendered":"<p>Cookies in PHP is done by using the statement setcookie() , this statement is available from the time when version 3 of PHP.<\/p>\n<p>int setcookie (string Name [, string Value [, int Expire [, string Path [, string Domain [, int Secure]]]]]);<\/p>\n<p>setcookie() defines a cookie that is sent the information from the header. Cookies are sent before any html tag; therefore, we call one of these statements before any tag  &lt;html&gt; or  &lt;head&gt;. This is a restriction of cookies, not for PHP.<\/p>\n<p>All messages, except the name are optional.<\/p>\n<ul>\n<li> Name . Name of the cookie. If we create a cookie only with its name, the cookie name is existing in the Client under said name will be deleted. We can also replace to any argument with an empty string(&#8220;&#8221;).<\/li>\n<li> Value . Value to be stored by the cookie in the Client.<\/li>\n<li> Expire . The argument expire is an integer argument that indicates the time of the cookie will be deleted in the time format returned by the UNIX statements time() and mktime(). Time() + N seconds of duration is commonly used to specify the duration of the cookie.<\/li>\n<li> Path . Subdirectory where the cookie has a value.<\/li>\n<li> Domain . Domain where the cookie has a value. If we establish www.yourdomain.com as domain, the cookie is not set for domain.com. Meanwhile, if we establish yourdomain.com as domain, the cookie is set as for yourdomain.com as for www. yourdomain.com.<\/li>\n<li> Secure . The secure indicates that the cookie will only be set by a secure HTTPS connection.<\/li>\n<\/ul>\n<p>Example<\/p>\n<p>setcookie(&#8220;Ron&#8221;, &#8220;Victor&#8221;, time()+3600,&#8221;\/&#8221;,&#8221;yahoo.com&#8221;);<\/p>\n<p>In this example, we set a user name cookie that has the value Victor , lasts 1 hour (3600 seconds) valid for the whole domain yahoo.com<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Cookies in PHP is done by using the statement setcookie() , this statement is available from the time when version 3 of PHP. int setcookie (string Name [, string Value [, int Expire [, string Path [, string Domain [, int Secure]]]]]); setcookie() defines a cookie that is sent the information from the header. Cookies [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[106,107],"class_list":["post-23","post","type-post","status-publish","format-standard","hentry","category-php","tag-cookies-in-php","tag-restriction-of-cookies"],"_links":{"self":[{"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/posts\/23","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/comments?post=23"}],"version-history":[{"count":4,"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/posts\/23\/revisions"}],"predecessor-version":[{"id":214,"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/posts\/23\/revisions\/214"}],"wp:attachment":[{"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/media?parent=23"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/categories?post=23"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/tags?post=23"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}