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:
getting premeture end of script headers error, can't find the problem

 



prsnlty
Deleted

Apr 4, 2000, 7:53 AM

Post #1 of 6 (486 views)
getting premeture end of script headers error, can't find the problem Can't Post

Hi,
I can't see what's wrong with this counter script. Please help?
The only error I get is "Premature end of script headers"
I've pasted the cgi below in hopes that someone will know what it is. Thank you :-)
Script:

#!/usr/bin/perl
##############################################################################
# c2ezcount Version 1.0 #
# Copyright 1998 Chad Casselman c2@websitereporter.com #
# Created 05/07/98 Last Modified 05/07/98 #
# URL: http:/www.websitereporter.com #
##############################################################################
##############################################################################
# COPYRIGHT NOTICE #
# Copyright 1998 Chad Casselman. All Rights Reserved. #
# #
# Counter may be used and modified free of charge by anyone so long as #
# this copyright notice and the comments above remain intact. By using this #
# code you agree to indemnify Chad Casselman from any liability that #
# might arise from it's use. #
# #
# Selling the code for this program without prior written consent is #
# expressly forbidden. In other words, please ask first before you try and #
# make money off of my program. #
# #
# Obtain permission before redistributing this software over the Internet or #
# in any other medium. In all cases copyright and header must remain intact.#
# #
##############################################################################

#######################################################################
#########################> USER OPTIONS <##############################
#######################################################################
# NOTE:
# Please set the first line of this file "#!/usr/bin/perl" to the location
# of perl on your server. If you don't know ask your system admin.
#
# To call the counter just insert the following code in your page after
# changing the "/location/to/script/" to the correct location.
# <!--#exec cgi="/location/to/script/c2ezcount.cgi"-->

$countfile = "/www/htdocs/allletters/c2ezcount.dat";
# Location to the file to hold the current count. Must be named c2ezcount.dat.
# Just change the path to the file.

$invisible = "1";
# "1": Counter will be invisible.
# "0": Counter will be visible.

$block_repeats = "1";
# "1": Blocks the reload button.
# "0": Does not block the reload button.

$private = "1";
# "1": Call must come from the site listed in @referers.
# "0": Call can be from ANY site ANYWHERE!

@referers = ("allletters.com","www.allletters.com","216.172.223.55");
# If private is "1" then set else leave at "0".
# Must have www.domain.com, domain.com, and IP Address.
# For more information see http://www.websitereporter.com/support

$digit_dir = "http://www.allletters.com/graphics";
# URL of the digits. Must be accessable via web browser.

$ending ="gif";
# Ending of digits, either "gif" or "jpg";

$same_digit_size = "1";
# "1": If the digits are SAME sizes. FASTER DISPLAY TIME
# "0": If the digits are DIFFERENT sizes. SLOWER DISPLAY TIME

$width = "1";
# Width of digits if the same size.

$height = "1";
# Height of digits if the same size.
#______________________________________________________________________
# If you still need help see http://www.websitereporter.com/support
# or please email mailto:c2ezcount@websitereporter.com
#######################################################################
########################> END USER OPTIONS <###########################
#######################################################################
### !!!! DO NOT CHANGE ANYTHING BELOW THIS LINE !!!! ###
#######################################################################

$host = $ENV{'REMOTE_HOST'};

if($private == 1) {
&check_referer;
}
&incrementcounter;
&check_invisibility;
$num = $length = length($count);
while ($num > 0) {
$NUMS{$num} = chop($count);
$num--;
}
$i = 1;
print "Content-type: text/html\n\n";
while ($i <= $length) {
if($same_digit_size == "1"){
print"<img src=\"$digit_dir/$NUMS{$i}\.gif\" width=$width height=$height\">";
}else{
print"<img src=\"$digit_dir/$NUMS{$i}\.$ending\">";
}
$i++;
}
exit(0);


#######################################################################
# Checks for valid counter call
#
sub check_referer {
if (@referers && $ENV{'HTTP_REFERER'}) {
foreach $referer (@referers) {
if ($ENV{'HTTP_REFERER'} =~ m/$referer/) {
$ref = 1;
last;
}
}
}
else {
$ref = 1;
}
if ($ref != 1) {
$badreferer = "$digit_dir/bad_referer.gif";
print "Location: $badreferer\n\n";
exit;
}
}
#
#
#######################################################################

#######################################################################
# Checks for invisible counter
#
sub check_invisibility {
if ($invisible == "1") {
print "Content-type: text/html\n\n";
print "\n";
exit(0);
}
}
#
#
#######################################################################

#######################################################################
# Increment the counter file
#
sub incrementcounter {
if (-e $countfile) {open(COUNT,"+<$countfile") &#0124; &#0124; die("Can't open $countfile: $!\n");
flock(COUNT,$lock);
$count = <COUNT>;
chop $count;
$lastvisitor = <COUNT>;
chop $lastvisitor;
if ( ($block_repeats == "1") && ($host == $lastvisitor) ) {
$dont_log = "1";
} else { $count++; }
$number = $count;
} else {open(COUNT,">$countfile") &#0124; &#0124; die("Can't open $countfile: $!\n");
flock(COUNT,$lock);
$count = 1;
}

seek(COUNT,0,0);
print (COUNT "$count\n$host\n");
flock(COUNT,$unlock);
close(COUNT);
}
#
#
#######################################################################




Jasmine
Administrator / Moderator

Apr 10, 2000, 3:28 PM

Post #2 of 6 (486 views)
Re: getting premeture end of script headers error, can't find the problem [In reply to] Can't Post

I've copied and pasted your entire script and it works fine on my server. Have you tried running it so it's not invisible? If so, do you get the same error?


prsnlty
Deleted

Apr 10, 2000, 8:41 PM

Post #3 of 6 (486 views)
Re: getting premeture end of script headers error, can't find the problem [In reply to] Can't Post

The error is now gone, and I still have it invisible. But, it's not recording counts.
I'm calling the script via SSI. I was told that this script is a multi page counter and supports invisibility and that's what I need. However, there were no install instructions except what is in the script it's self. It doesn't say if and how I need to place a page number in each call code (at this time I have not done so), I have chmod the .dat file to 777 and I no longer receive any errors. So I guess I'm lost at this point. BTW, I have yet to receive a reply to my e-mail from the creator of this script either. If anyone has any ideas I sure would love to hear them. Or even if you know of a counter that does what I need.
Thanks :-)


Jasmine
Administrator / Moderator

Apr 11, 2000, 6:36 AM

Post #4 of 6 (486 views)
Re: getting premeture end of script headers error, can't find the problem [In reply to] Can't Post

There's a whole bunch of counters at http://www.perlarchive.com/guide/Counters -- have you tried there?

It would be helpful if you had access to your error logs -- this would help isolate the problem as to why it's not incrementing. Have you tried to run the program in telnet?

[This message has been edited by Jasmine (edited 04-11-2000).]


prsnlty
Deleted

Apr 11, 2000, 8:31 AM

Post #5 of 6 (486 views)
Re: getting premeture end of script headers error, can't find the problem [In reply to] Can't Post

Hi Jasmine :-)
I do have access to my error logs..... no errors show. I can telnet but not to my site. My host set me up with a place to telnet for learning. No I haven't tried http://www.perlarchive.com/guide/counters, thank you :-0 I'm on my way.


prsnlty
Deleted

Apr 11, 2000, 9:30 AM

Post #6 of 6 (486 views)
Re: getting premeture end of script headers error, can't find the problem [In reply to] Can't Post

Thank you Jasmine for all your help. I just wanted to tell you that I got a counter that is perfect for my site. It was Cliff's counter. I set it up from start to finish in less that 2 minutes :-)

I need tracking too but it can wait for about a week since the site isn't open for business yet.
Thanks again!

 
 


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

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