{"id":2463,"date":"2019-11-30T08:13:14","date_gmt":"2019-11-30T08:13:14","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=2463"},"modified":"2022-02-17T07:13:49","modified_gmt":"2022-02-17T07:13:49","slug":"cannot-send-session-cookie-headers-already-sent-by","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/wordpress\/debugging-wordpress\/issues-degugging-wordpress\/cannot-send-session-cookie-headers-already-sent-by","title":{"rendered":"Cannot send session cookie &#8211; headers already sent by&#8230;"},"content":{"rendered":"\n<p>Full example of the error message<\/p>\n\n\n\n<p>Warning: session_start(): Cannot send session cookie &#8211; headers already sent by (output started at \/home\/mysitename\/public_html\/wp-content\/themes\/theme-child\/functions-myfile.php1:328) in \/home\/ mysitename \/public_html\/wp-content\/themes\/ theme -child\/functions- myfile2.php on line 711<\/p>\n\n\n\n<p>There&#8217;s a good explanation of this issue here: <a href=\"https:\/\/wordpress.stackexchange.com\/questions\/324762\/setting-cookie-with-init-hook-causes-header-already-sent\">https:\/\/wordpress.stackexchange.com\/questions\/324762\/setting-cookie-with-init-hook-causes-header-already-sent<\/a><\/p>\n\n\n\n<p>Basically is simply that you mustn&#8217;t have any whitespace after the closing ?&gt; of your themes php files, as theme and plugin files are loaded before init is called by wordpress, and init is what is best used for the session_start() call.  <\/p>\n\n\n\n<p>session_start() must be the first thing, before any whitespace even.  You can\u2019t set cookies, or send any other headers, if any of the content of the site is already sent.<\/p>\n\n\n\n<p>In the example above functions-myfile.php1 is the file with the issue, line 328 is a blank line after it closing ?&gt;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Full example of the error message Warning: session_start(): Cannot send session cookie &#8211; headers already sent by (output started at \/home\/mysitename\/public_html\/wp-content\/themes\/theme-child\/functions-myfile.php1:328) in \/home\/ mysitename \/public_html\/wp-content\/themes\/ theme -child\/functions- myfile2.php on line 711 There&#8217;s a good explanation of this issue here: https:\/\/wordpress.stackexchange.com\/questions\/324762\/setting-cookie-with-init-hook-causes-header-already-sent Basically is simply that you mustn&#8217;t have any whitespace after the closing ?&gt; of your [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[209],"tags":[],"class_list":["post-2463","post","type-post","status-publish","format-standard","hentry","category-issues-degugging-wordpress"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/2463","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/comments?post=2463"}],"version-history":[{"count":2,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/2463\/revisions"}],"predecessor-version":[{"id":2465,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/2463\/revisions\/2465"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=2463"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=2463"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=2463"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}