Okay, I solved the problem on my end. I can now log in, and everything’s hunky-dory!
What I did was use a tool that lets me easily do global Find/Replace using Regular Expressions (RegEx). For the “Find†RegEx, I used “
\n\s*\?>\s*$†and told it to Replace with “
\nâ€Â.
For those who don’t know RegEx syntax and want to know what that means:
- “\n†= line feed, the Unix line-separating character for text files, including .html and .php files (normally “^†would be used for “beginning of line,†but I’m doing the RegEx in full-file mode, not per-line mode, so “^†would only match the beginning of the whole file)
- “\s†= any single white-space character (space, tab, line feed, etc.), followed by “*†which means “the preceding character or other RegEx entity repeated zero or more times, so the combination “\s*†means “zero or more white-space characters (any combination of zero or more spaces, tabs, and/or line feeds, etc.)
- “\?†= since “?†is a RegEx syntax character itself (it means “repeat the previous character or other entity zero or one times†which you can think of as “the preceding character may or may not be there, but if so, would only be there onceâ€Â), if we really want to search for a question mark as itself, we have to “escape†it with a backslash
- “>†= just the right angle bracket (HTML closing tag-closing) character itself — need not be “escaped†— together with the previous, this forms the “?>†that we’re trying to eliminate at the ends of .php files
- “\s*†= as before, means zero or more white-space characters
- “$†= when RegEx is in line mode, this refers to the end of the line, but since we’re using full-file mode, it means the end of the file.
So, we’re telling it to Find all files where the last line of the file that does not itself consist entirely of white-space characters does consist of zero or more white-space characters followed by “
?>†followed by zero or more white-space characters followed by the end of the file itself. All of that last line is to be selected for replacement.
The Replace of “
\n†simply means to replace all of that selected stuff with a single Unix line-ending, an ordinary line feed character (for Windows servers, you’d use “
\r\n†instead to do a carriage return followed by a line feed).
In short, it completely erases the last non-blank line if and
only if it contains
only “
?>†with or without white space before and/or after the “
?>†and replaces it with a single completely blank line (not even a space) at the end of the file.
When I did this today on Version 3.1.2 with a few useful Plugins installed, I found only
one file in the 3.1.2 “core†that actually had some white space
after the “
?>†(which is what can cause problems by forcing the transmission of HTTP headers into a new HTTP Response prematurely): ironically enough, it was “
admin/template/error_checking.php†(at line 87). There had been lots more than that in the previous version I was using, namely, 3.1B.
In the Plugins that we use, there were two more files that had white space after the “
?>â€Â:
- plugins/DM_contactable/mail.php (line 26)
- plugins/user-management/ckeditor.php (this one ended [at line 40] in an empty “<?php
?>†code block, with white space after the “?>â€Â, so I deleted the entire empty and useless code block — it has actual HTML in it, mainly a “<script>†tag section.
Of course, there are other Plugins that I did
not check. But at the very least, edit those files and remove all white space after the “
?>â€Â.
Better yet, use the RegEx above (with a Find/Replace that allows you to preview each change before actually changing it, just in case) to find and replace <em>all</em> “
?>†that occur at the ends of .php files, whether or not there is white space after or even before them. They’re not needed for reasons I gave above, and their presence makes it all too easy that in some subsequent edit white space could accidentally wind up after them, triggering false HTTP Responses.
I
highly recommend that GetSimple release a Version 3.1.2a or 3.1.3 that has all file-terminating “
?>†removed from all files in core. All plugin developers should be notified to do likewise, and, like the Zend people, you may want to make it an official coding standard for GetSimple plugins that no .PHP files can end in “
?>†(especially not with white space following, but preferably not at all).