Page 1 of 1

PostPosted: Mon Sep 18, 2006 9:15 am
by Aoirthoir
This is the error I get:

Warning: Cannot modify header information - headers already sent by (output started at C:\Servers\xampp\htdocs\MedAct\conf\ApplicationDelegate.php:37) in C:\Servers\xampp\htdocs\libraries\dataface\actions\new_related_record.php on line 99

(No laughing..yes I am testing on a widoze machine....)

My ApplicationDelegate looks like this:

getLoggedInUser();
* if ( !isset($user) ) return Dataface_PermissionsTool::NO_ACCESS();
* // if the user is null then nobody is logged in... no access.
* // This will force a login prompt.
* $role = $user->val('ROLE');
* return Dataface_PermissionsTool::getRolePermissions($role);
* // Returns all of the permissions for the user's current role.
* }
*/

function block__html_title(){
echo "MyProg";

}


}
?>

And so line 37 is the last line of AppDelegate. If I remove the appDelegate I get no errors. So I am not sure if it is a medact error or a Xamp error. (Getting less and less fond of all versions of xamp..including their linux stuff....)

PostPosted: Mon Sep 18, 2006 9:20 am
by shannah
Your editor is adding whitespace after the closing ?> tag. Make sure there are no blank lines or even spaces after this. Some editors lie to you and make it appear that there is no trailing whitespace, when they have actually added some hidden chars.. try a few different editors. I have used Crimson Editor on Windows and it seems to be real about what whitespace there is.

-Steve

PostPosted: Mon Sep 18, 2006 9:21 am
by shannah
Alternatively you can use output buffering.

Add ob_start();
at the beginning of your index.php file

And ob_end_flush() at the end of it.

This will prevent whitespace from being output until the end.


-Steve

PostPosted: Mon Sep 18, 2006 9:27 am
by Aoirthoir
Thanks that solved it. I am using Notetab. It showed whitespace at the end. I just forgot that in some cases php doesnt allow that. You've put xamp back in my good graces :D

Thanks Mr. Steve.

PostPosted: Thu Sep 21, 2006 1:51 pm
by Aoirthoir
Mr. Steve,

Verifying this issue also. As I understand from memory, PHP does not allow whitespace at the end of a php file? Is this correct?

Also, what about the smarty templates files? Or other files in the database system. Is this a standard, no end whitespace? Or just the .php files?

Thank you kindly for your time.

PostPosted: Thu Sep 21, 2006 2:38 pm
by shannah
PHP does allow whitespace at the end of its files (following the ?>). The problem comes when we are sending headers (like redirects, cookies, etc..) to the browser. Headers must be sent before any output to the browser. Unfortunately when a PHP encounters white space at the end of the file it is the same as if you had done:


echo " ";

which writes to the browser - precluding the possibility of sending headers. The errors that you got were because Dataface was trying to send a redirect header after whitespace was already written to the browser.

This is not a problem with smarty templates, because they are compiled into PHP echo statements (essentially) that are only called when we want them to be called.

Another solution for this is to use PHP output buffering. Adding a call to ob_start() at the beginning of your app, will prevent output to the browser until:

a. Execution completes
b. or you call ob_end_flush()

Best regards

Steve

PostPosted: Thu Sep 21, 2006 3:08 pm
by Aoirthoir
Thank you kindly. Noted and closed.