in reply to a classic : 'Premature end of script headers' problem

This error means that your script does't write correct HTTP header (mostly because it's terminates before writing any header).

Possible reasons:

So one way to find the problem is try to run your script at shell and show us script output. It will be perfect if you run script from your webserver user account.