in reply to Premature end of script

Your script should print any errors to the webserver's error log. Perhaps reading and/or posting those errors along with your source would be more helpful.

Neil Watson
watson-wilson.ca