{"id":16505,"date":"2020-07-24T06:29:15","date_gmt":"2020-07-24T06:29:15","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=16505"},"modified":"2022-04-13T15:58:36","modified_gmt":"2022-04-13T15:58:36","slug":"php-intermediate-essential-guide-php-setting-cookies","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/php-intermediate-essential-guide-php-setting-cookies\/","title":{"rendered":"PHP intermediate essential guide- PHP setting cookies"},"content":{"rendered":"\n<p>In this blog, I am going to What is Php Cookies &amp; How to use Cookies in <strong>PHP<\/strong>. PHP cookies are the same in all languages but the different types to write in all. So in this lesson, we&#8217;re going to talk about cookies and other ways to track users. <strong>PHP<\/strong> use for storing data from the page into the client machine (remote browser) or track &amp; identifying return users. Cookies are part of the <strong>HTTP <\/strong>header <strong>setcookie()<\/strong> must be called before any output is sent to the browser. <\/p>\n\n\n\n<p>Just looking at the cookie page here and this gives us some more information about how to use cookies. So the first thing that we want to do is set a <strong>cookie<\/strong>. And when we set a cookie so we&#8217;re going to give it a name. We&#8217;re going to give it a value and we&#8217;re going to give it time. And whatever this time is we can actually add to the <strong>time<\/strong> so we can take the current value and we&#8217;re going to add our value into time.<\/p>\n\n\n\n<p>So this is a typical way to set a cookie. And again this is going to be when the cookie is going to expire. So with all cookies, you need to have this information. .cookie.So we&#8217;re going to give the cookie a name. So we&#8217;re just going to say the user and we&#8217;re going to give it a value and I set. So that&#8217;s all we have to do to set a cookie.<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/ajcotocus\/b0480d87219b10b94626f086db64069c.js\"><\/script>\n\n\n\n<p>When run first time in the browser then show as mention below<\/p>\n\n\n\n<p> <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"580\" height=\"239\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/07\/php-cookies.png\" alt=\"\" class=\"wp-image-16509\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/07\/php-cookies.png 580w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/07\/php-cookies-300x124.png 300w\" sizes=\"auto, (max-width: 580px) 100vw, 580px\" \/><\/figure>\n\n\n\n<p>after refresh the page then shown.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"567\" height=\"193\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/07\/php-cookies1.png\" alt=\"\" class=\"wp-image-16510\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/07\/php-cookies1.png 567w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/07\/php-cookies1-300x102.png 300w\" sizes=\"auto, (max-width: 567px) 100vw, 567px\" \/><\/figure>\n\n\n\n<p>when you refresh multiple time then show different-different value every time.<\/p>\n\n\n\n<figure class=\"wp-block-gallery columns-3 is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\"><ul class=\"blocks-gallery-grid\"><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"574\" height=\"233\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/07\/php-cookies3.png\" alt=\"\" data-id=\"16511\" data-full-url=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/07\/php-cookies3.png\" data-link=\"https:\/\/www.devopsschool.com\/blog\/?attachment_id=16511\" class=\"wp-image-16511\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/07\/php-cookies3.png 574w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/07\/php-cookies3-300x122.png 300w\" sizes=\"auto, (max-width: 574px) 100vw, 574px\" \/><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"607\" height=\"261\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/07\/php-cookies4.png\" alt=\"\" data-id=\"16512\" data-full-url=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/07\/php-cookies4.png\" data-link=\"https:\/\/www.devopsschool.com\/blog\/?attachment_id=16512\" class=\"wp-image-16512\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/07\/php-cookies4.png 607w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/07\/php-cookies4-300x129.png 300w\" sizes=\"auto, (max-width: 607px) 100vw, 607px\" \/><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"605\" height=\"261\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/07\/php-cookies5.png\" alt=\"\" data-id=\"16513\" data-full-url=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/07\/php-cookies5.png\" data-link=\"https:\/\/www.devopsschool.com\/blog\/?attachment_id=16513\" class=\"wp-image-16513\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/07\/php-cookies5.png 605w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/07\/php-cookies5-300x129.png 300w\" sizes=\"auto, (max-width: 605px) 100vw, 605px\" \/><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"593\" height=\"229\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/07\/php-cookies2.png\" alt=\"\" data-id=\"16514\" data-full-url=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/07\/php-cookies2.png\" data-link=\"https:\/\/www.devopsschool.com\/blog\/?attachment_id=16514\" class=\"wp-image-16514\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/07\/php-cookies2.png 593w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/07\/php-cookies2-300x116.png 300w\" sizes=\"auto, (max-width: 593px) 100vw, 593px\" \/><\/figure><\/li><\/ul><\/figure>\n\n\n<div class=\"epyt-gallery\" data-currpage=\"1\" id=\"epyt_gallery_74509\"><figure class=\"wp-block-embed wp-block-embed-youtube is-type-video is-provider-youtube epyt-figure\"><div class=\"wp-block-embed__wrapper\"><iframe loading=\"lazy\"  id=\"_ytid_12803\"  width=\"760\" height=\"427\"  data-origwidth=\"760\" data-origheight=\"427\" src=\"https:\/\/www.youtube.com\/embed\/?enablejsapi=1&#038;autoplay=0&#038;cc_load_policy=0&#038;cc_lang_pref=&#038;iv_load_policy=1&#038;loop=0&#038;rel=1&#038;fs=1&#038;playsinline=0&#038;autohide=2&#038;theme=dark&#038;color=red&#038;controls=1&#038;disablekb=0&#038;\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  data-epytgalleryid=\"epyt_gallery_74509\"  allow=\"fullscreen; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe><\/div><\/figure><div class=\"epyt-gallery-list\"><div>Sorry, there was a YouTube error.<\/div><\/div><\/div>\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this blog, I am going to What is Php Cookies &amp; How to use Cookies in PHP. PHP cookies are the same in all languages but&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[5150],"tags":[6283,6229,1122,6282,177,5484],"class_list":["post-16505","post","type-post","status-publish","format-standard","hentry","category-php","tag-cookies","tag-essential","tag-guide","tag-intermediate","tag-php","tag-setting"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/16505","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=16505"}],"version-history":[{"count":3,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/16505\/revisions"}],"predecessor-version":[{"id":24649,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/16505\/revisions\/24649"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=16505"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=16505"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=16505"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}