{"id":1179,"date":"2009-01-23T20:19:31","date_gmt":"2009-01-23T19:19:31","guid":{"rendered":"http:\/\/www.itwriting.com\/blog\/1179-microsoft-expression-web-causes-php-error.html"},"modified":"2009-01-23T20:19:31","modified_gmt":"2009-01-23T19:19:31","slug":"microsoft-expression-web-causes-php-error","status":"publish","type":"post","link":"https:\/\/www.itwriting.com\/blog\/1179-microsoft-expression-web-causes-php-error.html","title":{"rendered":"Microsoft Expression Web causes PHP error"},"content":{"rendered":"<p>I ran into a strange and surprising PHP error today. I\u2019m working on a little PHP application which has a login page. The login script calls session_start() to start or resume a PHP session. It was working OK so I decided to decorate the page a little (I was working in Eclipse). I like to try a variety of tools, so I ran up Microsoft\u2019s Expression Web, added an image, then re-ran the script to see how it looked.<\/p>\n<p>The answer was not good, because I now had an error:<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.itwriting.com\/images\/php-error.gif\" \/> <\/p>\n<blockquote>\n<p>Warning: session_start(): Cannot send session cookie \u2013 headers already sent<\/p>\n<\/blockquote>\n<p>I puzzled over this for some time. The error was in line 0 of my login page. I couldn\u2019t see anything that was different from before, except the static image that meant nothing to PHP.<\/p>\n<p>Eventually I worked it out. Eclipse (running on Windows) created the PHP files using ANSI. On saving, Expression Web silently changed them to UTF-8. That in itself was no bad thing \u2013 it\u2019s usually a better choice \u2013 though I reckon it should ask. The bigger problem was that Expression also added a BOM (byte order mark) to the beginning of the file. This is actually optional for UTF-8, and most non-Windows editors do not add it. It happens to flummox PHP, which interprets them who-knows-how and sends some output to the browser, preventing session_start from working.<\/p>\n<p>This is particularly painful to debug since most editors do not display the BOM; they simply use it to confirm the character set in use. So you can have file A which works, and file B which does not, and they are character-by-character identical.<\/p>\n<p>One way to see and remove the BOM is to open it with Edit.com, which does not understand it at all:<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.itwriting.com\/images\/bom.gif\" \/> <\/p>\n<\/p>\n<p>I guess both Expression and PHP could do better here. The bit that puzzles me is that I can\u2019t be the first to run into this. Doesn\u2019t Microsoft know that its UTF-8 BOM breaks PHP files, at least on the two versions I tried (<a href=\"http:\/\/www.apachefriends.org\/en\/xampp.html\" target=\"_blank\">XAMPP<\/a> on Windows and PHP 5.2.1 on Linux)? I can\u2019t even see a preference in Expression that would prevent it being written. And if you remove it, and then re-edit in Expression, it carefully writes it back. Unlike Adobe\u2019s Dreamweaver, which leaves well alone.<\/p>\n<p>PS if you want to know all about BOMs, <a href=\"http:\/\/unicode.org\/faq\/utf_bom.html\" target=\"_blank\">see here<\/a>.<\/p>\n<p><strong>Update<\/strong>: See comments \u2013 apparently this was fixed in Expression Web 2.0. Tina Clarke discusses the problem <a href=\"http:\/\/any-expression.com\/expression-web\/tutorials\/authoring-tab.htm\" target=\"_blank\">here<\/a>.<\/p>\n<\/p>\n<div class=\"wlWriterEditableSmartContent\" id=\"scid:0767317B-992E-4b12-91E0-4F059A8CECA8:ca25c5c1-1559-4141-960c-ebfb74a2b140\" style=\"padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px\">Technorati tags: <a href=\"http:\/\/technorati.com\/tags\/php\" rel=\"tag\">php<\/a>, <a href=\"http:\/\/technorati.com\/tags\/bom\" rel=\"tag\">bom<\/a>, <a href=\"http:\/\/technorati.com\/tags\/unicode\" rel=\"tag\">unicode<\/a>, <a href=\"http:\/\/technorati.com\/tags\/utf-8\" rel=\"tag\">utf-8<\/a>, <a href=\"http:\/\/technorati.com\/tags\/microsoft+expression+web\" rel=\"tag\">microsoft expression web<\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>I ran into a strange and surprising PHP error today. I\u2019m working on a little PHP application which has a login page. The login script calls session_start() to start or resume a PHP session. It was working OK so I decided to decorate the page a little (I was working in Eclipse). I like to &hellip; <a href=\"https:\/\/www.itwriting.com\/blog\/1179-microsoft-expression-web-causes-php-error.html\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Microsoft Expression Web causes PHP error<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,29,55,64,96,97],"tags":[],"class_list":["post-1179","post","type-post","status-publish","format-standard","hentry","category-adobe","category-eclipse","category-microsoft","category-php","category-web-authoring","category-windows"],"_links":{"self":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/posts\/1179","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/comments?post=1179"}],"version-history":[{"count":0,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/posts\/1179\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/media?parent=1179"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/categories?post=1179"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/tags?post=1179"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}