Click to See Complete Forum and Search --> : CGI Header Error
aztech4mac
08-12-2003, 01:21 PM
I have a small script to replace an empty file over an existing file. It doesn't print to anything except to the created file. I get a header error if i don't inclued print "Content-Type: text/html\n\n";. The problem with this is it creates a new empty html page and I need to stay on the same page where the CGI was called. I have other working scripts that don't use print "Content-Type: text/html\n\n"; what's the deal?
Jeff Mott
08-12-2003, 06:31 PM
I get a header error if i don't inclued print "Content-Type: text/html\n\n";This is because every CGI program is required to return an HTTP header. The problem with this is it creates a new empty html page and I need to stay on the same page where the CGI was calledYou'll have to use SSI for this.<!--#exec cgi="cgi-script" --> I have other working scripts that don't use print "Content-Type: text/html\n\n"; what's the deal?They probably return a different header, such as a redirect. But they still must return a header.
aztech4mac
08-12-2003, 11:29 PM
Thank for the reply. Unfortunatly this doesn't help. It seems I've painted myself into a corner. My CGI script writes a new empty file over an existing log file. I call a java script to confirm before writing the file. I use the statement; window.location.href = "/cgi-bin/ClearLog.cgi"; to call the CGI. <--#EXEC CGI ... won't work in the java script. How can I prevent the new empty page from appearing or how can I redirect back to the calling page with minimal delay. If you can think any other way to handle all this please feel free to suggest.
Jeff Mott
08-13-2003, 06:35 AM
use CGI;
my $cgi = CGI->new();
print $cgi->redirect('http://www.some-place.com/path/page.html');
aztech4mac
08-13-2003, 02:24 PM
Jeff I appreciate your response. I tried your solution but got this error; Status: 302 Moved Location: http://www.mysite.com/hitcount.shtml. If I have to use a redirect how can I finish building the blank html page and put a onLoad="history.go(-1)" in the Body tag. This is just a thought and I'm not even sure this will work. This approach doesn't reload the page and I would prefer to reload as this will update information that is changed by running the original CGI. What could I use to replace history.go(-1) to force the previous page to be reloaded.
Jeff Mott
08-13-2003, 04:40 PM
The code I gave was the solution for redirecting away from the blank page, not as the server side include. Note also that the print statment may need to be the last statement in the program.
You can use the META element in an HTML document to let the browser know the content needs to be refreshed. (see http://www.w3.org/TR/html401/struct/global.html#edef-META)
aztech4mac
08-13-2003, 08:26 PM
<Jeff Wrote>
The code I gave was the solution for redirecting away from the blank page, not as the server side include. Note also that the print statment may need to be the last statement in the program.
I really don't know what that means! I wan't to appologizes for all this. I guess I'm not being clear with my question or I'm confusing the issue somehow. I'll start all over from the beggining.
What do I need to do to modify the following code to either;
a) prevent a new blank html window appearing in the browser.
or
b) return to the url (window) calling the CGI.
#!D:\Perl\bin\Perl.exe
#################################################################
my $data = 'cp/scripts/perl/guestbook/E-Guest_db.txt';
open(file, ">$data");
print file "";
close(file);
print "Content-type: text/html\n\n";
Jeff Mott
08-16-2003, 01:34 PM
b) return to the url (window) calling the CGI.
print "Content-type: text/html\n\n";Change that line to...use CGI;
my $cgi = CGI->new();
print $cgi->redirect('http://www.some-place.com/path/page.html');