Question : Error in cgi script : Premature end of script headers

when i run this script key.cgi Iget in the browser  Internal Server Error

and when I look in the log files error_log i see this :

[Sat Aug 27 12:41:36 2005] [error] [client 213.16.179.235] Premature end of script headers: key.cgi, referer: http://sip-info.gr/key.html


the script is :

#!/bin/bash

if [ "$REQUEST_METHOD" = 'POST' ]
then
export QUERY_STRING=`cat`
fi
export EMAIL=`perl -e '($_)=$ENV{QUERY_STRING}=~/(?:^|&)email=([^&]*)/;s/%(\w\w)/pack"H2",$1/eg;print'`
echo 'content-type:text/html'

if [ "$REQUEST_METHOD" = 'POST' ]
then
export QUERY_STRING=`cat`
fi
export EMAIL=`perl -e '($_)=$ENV{QUERY_STRING}=~/(?:^|&)email=([^&]*)/;s/%(\w\w)/pack"H2",$1/eg;print'`
echo 'content-type:text/html'
echo
echo ' Done! '
echo "The generated key was sent at this address : $EMAIL"
echo '

'                                    

cd ~
dir2=`pwd`

cd /tmp
/usr/bin/ssh-keygen -t dsa -b 512 -N "" -f id_dsa >> /var/log/sshkey 2>&1
cat id_dsa.pub >$dir2/.ssh/authorized_keys
rm id_dsa.pub
rm id_dsa


echo -e "Subject:Your SSH Key\nFrom:Tophost.gr \n"`cat $dir2/.ssh/authorized_keys` | /usr/sbin/sendmail $EMAIL


and it was working perfectly in another website in the server..

Answer : Error in cgi script : Premature end of script headers

You should remove these lines:

if [ "$REQUEST_METHOD" = 'POST' ]
then
export QUERY_STRING=`cat`
fi
export EMAIL=`perl -e '($_)=$ENV{QUERY_STRING}=~/(?:^|&)email=([^&]*)/;s/%(\w\w)/pack"H2",$1/eg;print'`
echo 'content-type:text/html'

Your echo follow immediately by another echo 'content-type:text/html', which causes the problem.

The 'content-type:text/html' should follows by an empty line to set HTML doc type.  Your second one is correct since it follows by an empty echo.

GT


Random Solutions  
 
programming4us programming4us