Прошу вашей помощи, хабравчане!
Поставил на машину Apache и на Си написал скрипт для удалённого управления домашним роботом.
В браузере генерится страничка, куда я вывожу видео с камеры и обрабатываю клавиатуру. GET’ом отправляю команды на сервак, сам скрипт их обрабатывает, но в ответ приезжает страница с ошибкой, лог апача выдаёт: «premature end of script headers».
Что нужно сделать, чтобы после нажатия кнопки на клавиатуре и после выполнения скрипта страница в браузере не обновлялась и ничего другого не появлялось?
I get this error:
Premature end of script headers: version.cgi

2 Answers 2
You need to remove the extra backslash
EDIT
Also, the first line in the script looks wrong.
This should be the path to Perl, not httpd.
EDIT 2
Finally, this all would have been easier for you to solve if you added these two lines after the first line in your script:
And run the script on the command line with the -c -w flags to compile-check and warnings-check your script, ie perl -cw yourscript.cgi . This will give you line numbers of errors and warnings in your script.
Altogether, your script could look like this:
I get a «Premature end of script headers: contactform.cgi» error message when running the below script. What frustrates me is that I ran this as a .php on another server and it worked. However, I had to change servers and they only support CGI PHP. However, it doesn’t work. I don’t think the code is wrong, but take a look just in case.
I’ve read around and some have said it’s a permissions issue. Could this be the case for me?
I know that the «display_errors» and «error_reporting» statements will display errors in the error log, but if I don’t have access to the server, how can I check the logs?
16 Answers 16
I thought I would answer my own question for kicks and giggles (and for all those who might one day find themselves with the same error and no answers).
It was a file permission issue.
All files on my website were set to a permission of ‘644.’ Once I changed the permission level to 705 ( chmod 705 [ chmod 755 will also work]) everything was fine and dandy. Not that this matters, but I also changed the folder it was in to 701 (to hide it, but still be executable by the server).
I still don’t understand why my .PHP file worked on the other server when it was probably set to 644?? How could Apache execute the script without world permission?? Does Apache not need world permission?? Just a few questions I still have.