CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Premature End of Script Headers Error

 



bunky
newbie

Jul 6, 2001, 10:23 AM

Post #1 of 4 (652 views)
Premature End of Script Headers Error Can't Post

I get a premature end of script headers error on this script. Can anyone help?

#!/usr/local/bin/perl

$home = "http://www.somewhere.net/";


$redirect = "";

if ($ENV{'REMOTE_HOST'} eq 'aol.com') {$redirect = "http://www.domain.com/aol.html"}
if ($ENV{'REMOTE_HOST'} eq 'syndetics.net') {$redirect = "http://www.domain.com/synd.html"}
if ($ENV{'REMOTE_HOST'} eq 'earthlink.net') {$redirect = "http://www.domain.com/earth.html"}

if ($ENV{'REMOTE_ADDR'} == '127.0.0.1') {$redirect = "http://www.domain.com/page1.html"}
if ($ENV{'REMOTE_ADDR'} == '192.168.1.1') {$redirect = "http://www.domain.com/anotherpage.html"}
if ($ENV{'REMOTE_ADDR'} == '192.168.1.2') {$redirect = "http://www.domain.com/somethingelse.html"}

if ($redirect eq "") {$redirect="$home"}

print "Location: $redirect\n\n";



Pro_4
User

Jul 6, 2001, 10:39 AM

Post #2 of 4 (650 views)
Re: Premature End of Script Headers Error [In reply to] Can't Post

Well, for one is this a online type thing(going on a webpage?), if it is you need to include this:
use CGI qw(:all);
print header;
Also one thing i noticed was in your if loops your left out the semicolons:

Code
if ($ENV{'REMOTE_HOST'} eq 'aol.com') {$redirect = "http://www.domain.com/aol.html"; 
}
if ($ENV{'REMOTE_HOST'} eq 'syndetics.net') {$redirect = "http://www.domain.com/synd.html";
}
if ($ENV{'REMOTE_HOST'} eq 'earthlink.net') {$redirect = "http://www.domain.com/earth.html";
}

Other than that i didnt see anything wrong. Hope that helps :)

@letters = ('A'..'Z', 'a'..'z', '1'..'5', '_');
@i = ( '15', '43', '40');
print @letters [ @i, -1, 55];


mhx
Enthusiast / Moderator

Jul 6, 2001, 11:10 AM

Post #3 of 4 (646 views)
Re: Premature End of Script Headers Error [In reply to] Can't Post

Hi,

Pro_4 is right, you should use the CGI package. Also, you should include CGI::Carp. A nice header for a CGI script to start is normally

Code
#!/usr/local/bin/perl -wT 
use CGI qw(-no_debug :standard);
use CGI::Carp qw(fatalsToBrowser);
use strict;

The -no_debug is optional. It just stops CGI from always asking you for input when you're testing on the commandline.
The CGI::Carp will echo Perl errors to the browser, making script debugging a lot easier.
The use strict; will force clean Perl code.
With the CGI package, you can use

Code
print redirect($redirect);

to print a standard redirection header. I've also noticed that you try comparing IP addresses with ==, but as you actually compare strings, you have to use eq. Using -w would have warned you.
Pro_4, there's no need for semicolons at the end of a block. But if your block isn't a one-liner, I'd recommand putting a semicolon there, too.
Hope this helps,

-- Marcus



(This post was edited by mhx on Jul 6, 2001, 10:38 AM)


scuffed
stranger

Jul 7, 2001, 10:49 PM

Post #4 of 4 (628 views)
Re: Premature End of Script Headers Error [In reply to] Can't Post

hey dude put this
print "Pragma: no-cache\n";
right b4 the location line


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives