{"id":142,"date":"2019-09-03T01:00:27","date_gmt":"2019-09-02T19:15:27","guid":{"rendered":"http:\/\/localhost\/thecoder\/blog\/?p=142"},"modified":"2019-09-04T00:34:21","modified_gmt":"2019-09-03T18:49:21","slug":"php-cookies","status":"publish","type":"post","link":"https:\/\/coderpradip.com\/blog\/php-cookies\/","title":{"rendered":"How To Set Cookie in PHP For Remember Me"},"content":{"rendered":"<p>This page contains detailed information about how to set cookie in PHP for remember me.<\/p>\n<p>Let&#8217;s get started.<\/p>\n<h2>How to set cookie in PHP?<\/h2>\n<h3><strong>What is a Cookie?<\/strong><\/h3>\n<p>First of all, you all need to know what actually the cookie is. A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user&#8217;s computer. Each time the same computer requests a page with a browser, it will send the cookie too. With PHP, you can both create and retrieve cookie values.<\/p>\n<h3><strong>Creating\/setting a cookie<\/strong><\/h3>\n<p>to set a cookie there are many different ways, but I am showing you the only best way.<br \/>\nto create a cookie you need to write<\/p>\n<pre>\u00a0<var>setcookie(cookie_name,cookie_value);<\/var><\/pre>\n<p>Note: you can also set the time for the cookie(The expiry time after the cookie value)<\/p>\n<p>example:<\/p>\n<pre>[gistpen id=\"164\"]<\/pre>\n<p>Yeah, the cookie is now set.<\/p>\n<h3><strong>Printing\/Displaying the cookie value<\/strong><\/h3>\n<p>To print the cookie you need to write the following code:<\/p>\n<pre>echo $_COOKIE[\"MyName\"]; \r\n<\/pre>\n<p>for example:<\/p>\n<p>[gistpen id=&#8221;161&#8243;]<\/p>\n<h3><strong>Modifying the cookie<\/strong><\/h3>\n<p>actually modifying the cookie means re-setting the cookie again. in this post i have already set a cookie now i am gonna edit the cookie by setting the cookie value in the same cookie.<\/p>\n<p>so here we go:<\/p>\n<p>[gistpen id=&#8221;171&#8243;]<\/p>\n<h3><strong>Deleting the cookie<\/strong><\/h3>\n<p>to delete the cookie you have to set the expiry time. and the expiry time should be in -(it means before now).<\/p>\n<p>so let&#8217;s have a look<\/p>\n<p>[gistpen id=&#8221;178&#8243;]<\/p>\n<p>Note: You also have to set cookie value blank, so it will perform a better result.<\/p>\n<p>here I have destroyed the cookie before 600 Nano Seconds of the execution time.<\/p>\n<p>************************************************<\/p>\n<p>Do you love this article on <strong>how to set cookie in php<\/strong>? Let&#8217;s share this<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This page contains detailed information about how to set cookie in PHP for remember me. Let&#8217;s get started. How to set cookie in PHP? What is a Cookie? First of all, you all need to know what actually the cookie is. A cookie is often used to identify a user. A cookie is a small <a class=\"read-more\" href=\"https:\/\/coderpradip.com\/blog\/php-cookies\/\">&hellip;&nbsp;<span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-142","post","type-post","status-publish","format-standard","hentry","category-php"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How To Set Cookie in PHP For Remember Me - Pradip Adhikari<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/coderpradip.com\/blog\/php-cookies\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How To Set Cookie in PHP For Remember Me - Pradip Adhikari\" \/>\n<meta property=\"og:description\" content=\"This page contains detailed information about how to set cookie in PHP for remember me. Let&#8217;s get started. How to set cookie in PHP? What is a Cookie? First of all, you all need to know what actually the cookie is. A cookie is often used to identify a user. A cookie is a small &hellip;&nbsp;&rarr;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/coderpradip.com\/blog\/php-cookies\/\" \/>\n<meta property=\"og:site_name\" content=\"Pradip Adhikari\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/facebook.com\/notpradip\/\" \/>\n<meta property=\"article:author\" content=\"https:\/\/facebook.com\/notpradip\/\" \/>\n<meta property=\"article:published_time\" content=\"2019-09-02T19:15:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-09-03T18:49:21+00:00\" \/>\n<meta name=\"author\" content=\"Pradip Adhikari\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/notpradip\/\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Pradip Adhikari\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/coderpradip.com\/blog\/php-cookies\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/coderpradip.com\/blog\/php-cookies\/\"},\"author\":{\"name\":\"Pradip Adhikari\",\"@id\":\"https:\/\/coderpradip.com\/blog\/#\/schema\/person\/f7a455883d474da73ee7730e4cc8a5d7\"},\"headline\":\"How To Set Cookie in PHP For Remember Me\",\"datePublished\":\"2019-09-02T19:15:27+00:00\",\"dateModified\":\"2019-09-03T18:49:21+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/coderpradip.com\/blog\/php-cookies\/\"},\"wordCount\":294,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/coderpradip.com\/blog\/#\/schema\/person\/f7a455883d474da73ee7730e4cc8a5d7\"},\"articleSection\":[\"PHP\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/coderpradip.com\/blog\/php-cookies\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/coderpradip.com\/blog\/php-cookies\/\",\"url\":\"https:\/\/coderpradip.com\/blog\/php-cookies\/\",\"name\":\"How To Set Cookie in PHP For Remember Me - Pradip Adhikari\",\"isPartOf\":{\"@id\":\"https:\/\/coderpradip.com\/blog\/#website\"},\"datePublished\":\"2019-09-02T19:15:27+00:00\",\"dateModified\":\"2019-09-03T18:49:21+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/coderpradip.com\/blog\/php-cookies\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/coderpradip.com\/blog\/php-cookies\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/coderpradip.com\/blog\/php-cookies\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/coderpradip.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Programming\",\"item\":\"https:\/\/coderpradip.com\/blog\/category\/programming\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"PHP\",\"item\":\"https:\/\/coderpradip.com\/blog\/category\/programming\/php\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"How To Set Cookie in PHP For Remember Me\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/coderpradip.com\/blog\/#website\",\"url\":\"https:\/\/coderpradip.com\/blog\/\",\"name\":\"Pradip Adhikari\",\"description\":\"Blog\",\"publisher\":{\"@id\":\"https:\/\/coderpradip.com\/blog\/#\/schema\/person\/f7a455883d474da73ee7730e4cc8a5d7\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/coderpradip.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/coderpradip.com\/blog\/#\/schema\/person\/f7a455883d474da73ee7730e4cc8a5d7\",\"name\":\"Pradip Adhikari\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/coderpradip.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/coderpradip.com\/blog\/wp-content\/uploads\/2023\/01\/Pradip-Adhikari.png\",\"contentUrl\":\"https:\/\/coderpradip.com\/blog\/wp-content\/uploads\/2023\/01\/Pradip-Adhikari.png\",\"width\":954,\"height\":1069,\"caption\":\"Pradip Adhikari\"},\"logo\":{\"@id\":\"https:\/\/coderpradip.com\/blog\/#\/schema\/person\/image\/\"},\"description\":\"Tech Geek and Author\",\"sameAs\":[\"http:\/\/coderpradip.com\/\",\"https:\/\/facebook.com\/notpradip\/\",\"https:\/\/instagram.com\/notpradip\/\",\"https:\/\/linkedin.com\/in\/notpradip\/\",\"https:\/\/x.com\/https:\/\/twitter.com\/notpradip\/\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How To Set Cookie in PHP For Remember Me - Pradip Adhikari","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/coderpradip.com\/blog\/php-cookies\/","og_locale":"en_US","og_type":"article","og_title":"How To Set Cookie in PHP For Remember Me - Pradip Adhikari","og_description":"This page contains detailed information about how to set cookie in PHP for remember me. Let&#8217;s get started. How to set cookie in PHP? What is a Cookie? First of all, you all need to know what actually the cookie is. A cookie is often used to identify a user. A cookie is a small &hellip;&nbsp;&rarr;","og_url":"https:\/\/coderpradip.com\/blog\/php-cookies\/","og_site_name":"Pradip Adhikari","article_publisher":"https:\/\/facebook.com\/notpradip\/","article_author":"https:\/\/facebook.com\/notpradip\/","article_published_time":"2019-09-02T19:15:27+00:00","article_modified_time":"2019-09-03T18:49:21+00:00","author":"Pradip Adhikari","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/notpradip\/","twitter_misc":{"Written by":"Pradip Adhikari","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/coderpradip.com\/blog\/php-cookies\/#article","isPartOf":{"@id":"https:\/\/coderpradip.com\/blog\/php-cookies\/"},"author":{"name":"Pradip Adhikari","@id":"https:\/\/coderpradip.com\/blog\/#\/schema\/person\/f7a455883d474da73ee7730e4cc8a5d7"},"headline":"How To Set Cookie in PHP For Remember Me","datePublished":"2019-09-02T19:15:27+00:00","dateModified":"2019-09-03T18:49:21+00:00","mainEntityOfPage":{"@id":"https:\/\/coderpradip.com\/blog\/php-cookies\/"},"wordCount":294,"commentCount":0,"publisher":{"@id":"https:\/\/coderpradip.com\/blog\/#\/schema\/person\/f7a455883d474da73ee7730e4cc8a5d7"},"articleSection":["PHP"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/coderpradip.com\/blog\/php-cookies\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/coderpradip.com\/blog\/php-cookies\/","url":"https:\/\/coderpradip.com\/blog\/php-cookies\/","name":"How To Set Cookie in PHP For Remember Me - Pradip Adhikari","isPartOf":{"@id":"https:\/\/coderpradip.com\/blog\/#website"},"datePublished":"2019-09-02T19:15:27+00:00","dateModified":"2019-09-03T18:49:21+00:00","breadcrumb":{"@id":"https:\/\/coderpradip.com\/blog\/php-cookies\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/coderpradip.com\/blog\/php-cookies\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/coderpradip.com\/blog\/php-cookies\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/coderpradip.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Programming","item":"https:\/\/coderpradip.com\/blog\/category\/programming\/"},{"@type":"ListItem","position":3,"name":"PHP","item":"https:\/\/coderpradip.com\/blog\/category\/programming\/php\/"},{"@type":"ListItem","position":4,"name":"How To Set Cookie in PHP For Remember Me"}]},{"@type":"WebSite","@id":"https:\/\/coderpradip.com\/blog\/#website","url":"https:\/\/coderpradip.com\/blog\/","name":"Pradip Adhikari","description":"Blog","publisher":{"@id":"https:\/\/coderpradip.com\/blog\/#\/schema\/person\/f7a455883d474da73ee7730e4cc8a5d7"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/coderpradip.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/coderpradip.com\/blog\/#\/schema\/person\/f7a455883d474da73ee7730e4cc8a5d7","name":"Pradip Adhikari","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/coderpradip.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/coderpradip.com\/blog\/wp-content\/uploads\/2023\/01\/Pradip-Adhikari.png","contentUrl":"https:\/\/coderpradip.com\/blog\/wp-content\/uploads\/2023\/01\/Pradip-Adhikari.png","width":954,"height":1069,"caption":"Pradip Adhikari"},"logo":{"@id":"https:\/\/coderpradip.com\/blog\/#\/schema\/person\/image\/"},"description":"Tech Geek and Author","sameAs":["http:\/\/coderpradip.com\/","https:\/\/facebook.com\/notpradip\/","https:\/\/instagram.com\/notpradip\/","https:\/\/linkedin.com\/in\/notpradip\/","https:\/\/x.com\/https:\/\/twitter.com\/notpradip\/"]}]}},"_links":{"self":[{"href":"https:\/\/coderpradip.com\/blog\/wp-json\/wp\/v2\/posts\/142","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/coderpradip.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/coderpradip.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/coderpradip.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/coderpradip.com\/blog\/wp-json\/wp\/v2\/comments?post=142"}],"version-history":[{"count":0,"href":"https:\/\/coderpradip.com\/blog\/wp-json\/wp\/v2\/posts\/142\/revisions"}],"wp:attachment":[{"href":"https:\/\/coderpradip.com\/blog\/wp-json\/wp\/v2\/media?parent=142"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/coderpradip.com\/blog\/wp-json\/wp\/v2\/categories?post=142"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/coderpradip.com\/blog\/wp-json\/wp\/v2\/tags?post=142"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}