|Warning: session_start() [function.session-start]: Cannot send session cookie – headers already sent by (output started at /media/truecrypt1/htdocs/……/SugarEnt-Full-5.5.1/include/entryPoint.php:1) in /media/truecrypt1/htdocs/……/SugarEnt-Full-5.5.1/include/MVC/SugarApplication.php on line 410|
How many times have we seen an error like this at one time or another? Or many you just see add text in the upper left hand corner of the screen. Sometimes it is easy to find and sometimes it becomes an out of control hunt through SugarCRM’s thousands of files.
What causes error like this are extraneous characters outside of the PHP beginning and end script tags. So somewhere a file has an extra space (or any other character) at the very beginning or end of the script. Something like this
I have seen people do things like this for debugging and then forget to remove it and a week later when they get complaints from users, the hunt is on because they completely forgot what files they edited. Now sometimes the unwanted text is in the file referenced in the error, in this case entryPoint.php, but that is not always the case. If you have deep includes or output buffer capturing then the characters could be anywhere. So if it is not in that file this is what I do.
Get a list of recently edited files
In linux you would just run a command like
find . -mtime -3
and that would give you all the files edited in the last 3 days. I am sure there is a pretty "point and click" way to do the same thing in windows, you'll have to Google that if your stuck pointing and clicking on your server. From that list you might be able to jog your memory and at worst you will have a short list of files to start with. But lets say that the file was edited a while ago or you have done alot of work since then and this list of files is useless. When then we will need a more complicated script to actually look at each file and flag those that have characters outside the script tags. Something like this.
It may not be pretty but it works. This will produce two lists of files, one listing all the files that have something before the script tag (<?php) and one listing all files after the script tag (?>). You would just run it with the “php -f” command from inside your SugarCRM directory. Something like this.
ken@ken-laptop:/opt/lampp/htdocs/........./SugarEnt-Full-5.5.1$ php -f ../../FindWhiteSpace.php Files with issue at the beginning of the file --------------------------------------- ./cache/themes/Sugar/pathCache.php -First Character: "a" (97) ./cache/upload/upgrades/module/Test_5512010_03_23_160222-manifest.php -First Character: "" (32) ./cache/upload/upgrades/temp/2rDpev/manifest.php -First Character: "" (32) ./custom/modulebuilder/builds/Test_551/manifest.php -First Character: "" (32) ./include/SugarObjects/templates/issue/language/application/en_us.lang.php -First Character: "" (32) ./include/domit_rss/example_domit_rss_lite.php -First Character: "&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;" (60) ./include/domit_rss/testing_domitrss.php -First Character: "&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;" (60) ./include/entryPoint.php -First Character: "1" (49) ./include/phpmailer/language/phpmailer.lang-ja.php -First Character: "" (0) ./install/language/pt_br.lang.php -First Character: "�" (239) ./modules/Administration/undoupdateclass.php -First Character: "" (10) ./modules/Campaigns/Subscriptions.php -First Character: "" (32) ./modules/Home/PopupSugar.php -First Character: "&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;" (60) ./modules/MailMerge/Step2.php -First Character: "" (32) Files with issue at the end of the file --------------------------------------- ./cache/smarty/templates_c/%%03^03B^03B20820%%singletabmenu.tpl.php ./cache/smarty/templates_c/%%D4^D4D^D4D49BFB%%PackageForm.tpl.php ./cache/upload/upgrades/temp/2rDpev/SugarModules/modules/KAB_Test551/metadata/popupdefs.php ./custom/modulebuilder/builds/Test_551/SugarModules/modules/KAB_Test551/metadata/popupdefs.php ./custom/modulebuilder/packages/Test_551/modules/Test551/metadata/popupdefs.php ./include/Popups/Popup_picker.php ./include/SugarFields/Parsers/DetailViewMetaParser.php ./include/SugarFields/Parsers/SearchFormMetaParser.php ./include/SugarObjects/templates/basic/metadata/popupdefs.php ./include/SugarObjects/templates/company/metadata/editviewdefs.php ./include/SugarObjects/templates/company/metadata/popupdefs.php ./include/SugarObjects/templates/company/metadata/searchdefs.php ./include/SugarObjects/templates/file/language/en_us.lang.php ./include/SugarObjects/templates/file/metadata/SearchFields.php ./include/SugarObjects/templates/file/metadata/listviewdefs.php ./include/SugarObjects/templates/file/metadata/searchdefs.php
Again, there will be alot of false positives on this list (I submitted a bug to the engineers to see if we can get this list shortened up a bit) but it is a great start. From thousands of files down to a few dozen.