{"id":7578,"date":"2022-03-28T07:00:34","date_gmt":"2022-03-28T01:30:34","guid":{"rendered":"https:\/\/selfimagination.in\/tips\/?p=7578"},"modified":"2022-07-19T15:43:41","modified_gmt":"2022-07-19T10:13:41","slug":"setcookie-not-working-cannot-modify-header-information","status":"publish","type":"post","link":"https:\/\/selfimagination.in\/tips\/setcookie-not-working-cannot-modify-header-information\/","title":{"rendered":"Setcookie Not Working &#8211; Cannot modify header information"},"content":{"rendered":"\n<p>\u091c\u092c \u092d\u0940 \u0939\u092e \u0939\u092e\u093e\u0930\u0947 \u0915\u093f\u0938\u0940 PHP Program \u0938\u0947 Cookie \u0915\u094b Set \u0915\u0930\u0924\u0947 \u0939\u0948\u0902 \u0924\u092c \u0939\u094b \u0938\u0915\u0924\u093e \u0939\u0948\u0902 \u0924\u092c setcookie not working \u0939\u094b, \u0906\u0907\u090f \u0938\u092e\u091d\u0924\u0947 \u0939\u0948\u0902 \u0915\u0940 setcookie \u0915\u093f\u0928 \u0915\u093e\u0930\u0923\u094b\u0902 \u0938\u0947 work \u0928\u0939\u0940\u0902 \u0915\u0930\u0924\u0940 \u0939\u0948\u0902 \u0964 <\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"block-0d052c7b-f7f4-4c45-be13-d8f4bf48cb28\">Problem : setcookie not working due to Cannot modify header information<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">PHP Warning:  Cannot modify header information - headers already sent by (output started at ....index.php:4) in .....index.php on line 5\n\nWhen you use setcookie then cookie not stored.<\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">&lt;?php if (isset($_POST['BtnName']))\n{\n        $u_nm = $_POST['u_nm'];\n        echo $u_nm;   \n\tsetcookie(\"CookieName\", $u_nm, time() + 86400, \"\/\");\n}<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>\u091c\u092c \u092d\u0940 \u0939\u092e PHP setcookie Function \u0915\u093e \u0909\u092a\u092f\u094b\u0917 \u0915\u0930\u0924\u0947 \u0939\u0948\u0902 \u0924\u092c \u0939\u092e\u0947 PHP Warning:  Cannot modify header information &#8211; headers already sent by (output started at .. Error \u0926\u093f\u0916\u093e\u0908 \u0926\u0947\u0924\u0940 \u0939\u0948\u0902 \u0914\u0930 \u0938\u093e\u0925 \u092e\u0947 Cookies \u092e\u0947 Value \u092d\u0940 Store \u0928\u0939\u0940\u0902 \u0939\u094b\u0924\u0940 \u0939\u0948\u0902 \u0964 <\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"solution-remove\">Solution <\/h3>\n\n\n\n<p><strong>Remove any HTML Code or PHP Echo Tag before setcookie  Function. <\/strong><\/p>\n\n\n\n<p>\u0906\u092a\u0915\u094b \u0915\u0939\u0940 \u092a\u0930 \u092d\u0940 Cannot modify header information &#8211; headers already sent by .. Error \u0926\u093f\u0916\u093e\u0908 \u0926\u0947 \u0924\u092c \u0906\u092a \u0938\u092c\u0938\u0947 \u092a\u0939\u0932\u0947 \u092f\u0939 \u0926\u0947\u0916\u0928\u093e \u0915\u0940 \u0907\u0938 Line \u0915\u0947 \u092a\u0939\u0932\u0947 \u0915\u094b\u0908 HTML \u092a\u0930 \u0915\u0941\u091b \u092d\u0940 Print \u0915\u0930\u0928\u0947 \u0915\u093e \u092f\u093e Direct \u0939\u0940 \u0915\u094b\u0908 HTML \u0915\u093e Code \u0932\u093f\u0916\u093e \u0939\u0941\u0906 \u0939\u094b \u0924\u094b Use Remove \u0915\u0930\u0928\u093e \u0939\u0948\u0902 \u0964  ?<\/p>\n\n\n\n<p>\u091c\u0948\u0938\u0947 \u0909\u092a\u0930\u094b\u0915\u094d\u0924 Example \u092e\u0947 Echo \u0932\u093f\u0916\u093e \u0939\u0948\u0902 , \u091c\u093f\u0938\u0915\u0947 \u0915\u093e\u0930\u0923 \u092f\u0939 Error \u0906 \u0930\u0939\u0940 \u0939\u0948\u0902 \u0964 <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">&lt;?php if (isset($_POST['BtnName']))\n{\n        $u_nm = $_POST['u_nm'];\n         \/\/        echo $u_nm;   \n\tsetcookie(\"CookieName\", $u_nm, time() + 86400, \"\/\");\n}<\/code><\/pre>\n\n\n\n<p>\u0906\u092a\u0915\u094b echo \u092f\u093e \u0915\u094b\u0908 \u092d\u0940 HTML Code \u0932\u093f\u0916\u093e \u0939\u0948\u0902 \u0924\u094b \u0909\u0938\u0947 Comment \u0915\u0930\u0928\u093e \u0939\u094b\u0917\u093e \u0964 <\/p>\n\n\n\n<p>\u091c\u0948\u0938\u0947 \u0939\u0940 \u0906\u092a echo \u092f\u093e \u0905\u0928\u094d\u092f Code Comment \u0915\u0930\u0947\u0902\u0917\u0947 \u0914\u0930 Page \u0915\u094b Refresh \u0915\u0930\u0947\u0902\u0917\u0947 Automatically Error Solve \u0939\u094b \u091c\u093e\u090f\u0917\u0940 \u0964 <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"cannot-modify-header-information\">Cannot modify header information<\/h2>\n\n\n\n<p><strong>Problem :<\/strong> \u091c\u092c \u0906\u092a header() function \u0915\u093e \u0909\u092a\u092f\u094b\u0917 \u0915\u0930\u0924\u0947 \u0939\u0948\u0902 \u091c\u094b \u0915\u0940 \u0906\u092a \u0915\u094b\u0908 \u092d\u0940 Code Start \u0939\u094b\u0928\u0947 \u0938\u0947 \u092a\u0939\u0932\u0947 \u0939\u0940 \u0932\u093f\u0916\u0924\u0947 \u0939\u0948\u0902 \u0909\u0938\u0915\u0947 \u092c\u093e\u0935\u091c\u0942\u0926 \u092d\u0940 Cannot modify header information Error \u0906\u0928\u0947 \u0932\u0917\u0924\u0940 \u0939\u0948\u0902 <\/p>\n\n\n\n<p><strong>Solution :<\/strong> \u0907\u0938\u0915\u0947 \u0932\u093f\u090f \u0906\u092a \u0938\u092c\u0938\u0947 \u092a\u0939\u0932\u0940 \u0932\u093e\u0907\u0928 \u092e\u0947 header function \u0915\u094b \u0932\u093f\u0916\u0928\u093e \u0939\u094b\u0924\u093e \u0939\u0948\u0902 \u092f\u0926\u093f \u091c\u094b &lt;?php tag \u091a\u093e\u0932\u0942 \u0915\u093f\u092f\u093e \u0939\u0948\u0902 \u0935\u0939 \u0926\u0942\u0938\u0930\u0940 \u0932\u093e\u0907\u0928 \u092a\u0930 \u0939\u0941\u0906 \u0924\u094b \u0907\u0938 \u0924\u0930\u0939 \u0915\u0940 Error \u0906\u0928\u0947 \u0932\u0917\u0947\u0917\u0940 \u0964 <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u0939\u092e-\u0930-\u0905\u0928-\u092f-\u0906\u0930-\u091f-\u0915\u0932\"><strong>\u0939\u092e\u093e\u0930\u0947 \u0905\u0928\u094d\u092f \u0906\u0930\u094d\u091f\u093f\u0915\u0932<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/selfimagination.in\/tips\/mysql-function\/\">MySQL Function<\/a><\/li><li><a href=\"https:\/\/selfimagination.in\/tips\/mysql-stored-procedure\/\">MySQL Stored Procedure<\/a><\/li><li><a href=\"https:\/\/selfimagination.in\/tips\/get-post-method\/\">PHP Get \/Post Method \u0915\u0947 \u092c\u093e\u0930\u0947 \u092e\u0947\u0902 \u091c\u093e\u0928\u0947<\/a><\/li><li><a href=\"https:\/\/selfimagination.in\/tips\/php-math-function\/\">PHP Math Function \u0915\u0947 \u092c\u093e\u0930\u0947 \u092e\u0947\u0902 \u091c\u093e\u0928\u0947<\/a><\/li><li><a href=\"https:\/\/selfimagination.in\/tips\/learn-cpp-from-c\/\">C \u0938\u0947 C ++ \u0938\u0940\u0916\u0947 \u0938\u0930\u0932 \u0936\u092c\u094d\u0926\u094b\u0902 \u092e\u0947\u0902<\/a><\/li><li><a href=\"https:\/\/selfimagination.in\/tips\/php-variables\/\">PHP Variable \u0915\u0947 \u092c\u093e\u0930\u0947 \u092e\u0947\u0902 \u091c\u093e\u0928\u0947<\/a><\/li><li><a href=\"https:\/\/selfimagination.in\/tips\/arduino-control-structure\/\">Arduino Control Structure<\/a>\u00a0<\/li><li><a href=\"https:\/\/selfimagination.in\/tips\/c-union\/\">Union in C<\/a><\/li><li><a href=\"https:\/\/selfimagination.in\/tips\/c-pointer\/\">Declaration of Pointer in C<\/a><\/li><li><a href=\"https:\/\/selfimagination.in\/tips\/search-jquery\/\">jQuery Search Filter<\/a><\/li><li><a href=\"https:\/\/selfimagination.in\/tips\/mysql-table-create-alter-drop\/\">MySQL Create Table | Alter Table | Drop Table<\/a><\/li><li><a href=\"https:\/\/selfimagination.in\/tips\/api-using-node-react-express-mysql\/\">API Using NODE REACT EXPRESS MYSQL SEQUELIZE (For Backend OR Server Side)<\/a><\/li><li><a href=\"https:\/\/selfimagination.in\/tips\/cpanel\/\">CPANEL In Hindi<\/a><\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u091c\u092c \u092d\u0940 \u0939\u092e \u0939\u092e\u093e\u0930\u0947 \u0915\u093f\u0938\u0940 PHP Program \u0938\u0947 Cookie \u0915\u094b Set \u0915\u0930\u0924\u0947 \u0939\u0948\u0902 \u0924\u092c \u0939\u094b \u0938\u0915\u0924\u093e \u0939\u0948\u0902 \u0924\u092c setcookie not working \u0939\u094b, \u0906\u0907\u090f \u0938\u092e\u091d\u0924\u0947 \u0939\u0948\u0902 \u0915\u0940 setcookie \u0915\u093f\u0928 \u0915\u093e\u0930\u0923\u094b\u0902 \u0938\u0947 work \u0928\u0939\u0940\u0902 \u0915\u0930\u0924\u0940 \u0939\u0948\u0902 \u0964 Problem : setcookie not working due to Cannot modify header information PHP Warning: Cannot modify header information &#8211; headers already [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":7673,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[10,3],"tags":[],"class_list":["post-7578","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-solution","category-php"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2022\/02\/set-cookie-not-working.jpg?fit=1200%2C628&ssl=1","_links":{"self":[{"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/posts\/7578","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/comments?post=7578"}],"version-history":[{"count":16,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/posts\/7578\/revisions"}],"predecessor-version":[{"id":8717,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/posts\/7578\/revisions\/8717"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/media\/7673"}],"wp:attachment":[{"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/media?parent=7578"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/categories?post=7578"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/tags?post=7578"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}