markc Posted September 26, 2003 Posted September 26, 2003 Help, I am a little new to cgi/perl scripting. Here is my problem. I am trying to add a counter to my index.html web page and it is not working. I am trying to use the Perl script bscounter v. 2.0.2 (found at http://www.stanback.net/programming/bscounter) and for some reason I can't get it to work. It is like the script exits right away. I am trying to use his "gd-count.cgi" perl script. I created a folder called bscounter in my cgi-bin folder (which is found in my public_html folder). I also tried moving all of the bscounter images (png and gif) from his image folder to the images folder (found in my public_html folder) because I thought I may not be able to read gif and/or png files in the cgi-bin folder. In the gd-count.cgi perl script file I just changed the variables: @allowed from "stanback.net", "gotmod.com", "spilledink.org" to "mectjv.com", "www.mectjv.com". Which will be my website. I also changed the variable: @$digits_dir from "./images/digits/" to "../../images/digits/" This is because the images folder is two folders up from the gd-count.cgi script. I also changed the variable: $data_dir from "/home/sites/www.stanback.net/web/cgi-bin/bscounter/data/" to "/home/mectjvc/public_html/cgi-bin/bscounter/data/". Here is the line of code that I have used in my index.html file to call the gd-count.cgi script: ><img src="/cgi-bin/bscounter/gd-count.cgi?page=hpcounter&style=plain_b&x=17&y=27&nbdigits=6"> Here is what I am using for permissions: index.html 644 cgi-bin folder 755 bscounter folder 755 gd-count.cgi 755 data folder (found in the bscounter folder) 777 I was originally getting some errors previously in the error log but now I get nothing except: "Premature end of script headers: /home/mectjvc/public_html/cgi-bin/bscounter/gd-count.cgi". Here is the first few lines of the gd-count.cgi script: >#!/usr/bin/perl -w use strict; use Fcntl ':flock'; use GD; I have tried to put "print" statements in the gd-count.cgi perl script, but I get nothing. It's like it will not call the gd-count.cgi script. Could it be something in my .htaccess file that is preventing the script from running? There is a statement in the gd-count.cgi perl script that checks the @allowed variable against the ($ENV{HTTP_REFERER} variable. If it is not found (no match), then it exits the script. But it seems it never gets that far because the "print" statements I placed in the script for debugging purposes never show up on my browser web page. I have attached the gd-count.cgi perl script if needed. I would appreciate any help. Thanks. Mark gd_count.cgi Quote
Guest schussat Posted September 27, 2003 Posted September 27, 2003 Hi markc- "Premature end of script headers" are kind of a catch-all, and they're sometimes hard to diagnose. You mentioned that you've put some "print" commands into the script for debugging purposes, and my guess is that they're at least part of the problem. The script is sending a content-type of img/jpg, and that won't jive with outputting any text. Do you still get the error if you remove all the debugging lines? Be sure to leave the >print "Content-type: image/png\n\n"; print $image->png; lines in! That's where the image actually gets displayed. Quote
markc Posted September 27, 2003 Author Posted September 27, 2003 Hello - schussat, Thanks for responding. The file that I included with the post was a "clean" version of the script. It does not contain any "debug" print statements that I personally added to the script. The two print lines you mentioned have remained untouched in the script. I only changed the three variable lines at the top of the script as mentioned in the original post. You are correct about "Premature end of script headers" errors being hard to diagnose. The bscounter counter looks like a nice counter script with nice reporting. So I would like to use it. There is an option of using the alternative script called "setup.cgi" but it requires you to use a server side include which I was trying to avoid if possible. Thanks again for your reply. Mark Quote
Guest schussat Posted September 27, 2003 Posted September 27, 2003 Thanks for responding. The file that I included with the post was a "clean" version of the script. It does not contain any "debug" print statements that I personally added to the script. The two print lines you mentioned have remained untouched in the script. I only changed the three variable lines at the top of the script as mentioned in the original post. Thanks for clarifying -- I wasn't sure if you had added your debug lines before or after you started to encounter the error. But, it sounds like the error appears with our without them. Wow, it's been a long time since I did any CGI ... grad school has de-skilled me, I guess. The file permissions all look right, the location of everything looks correct. Do you have GD.pm installed? The bscount docs indicate that it's required. I would expect a more specific error message if that was the problem, but it's worth a try. -Alan Quote
markc Posted September 27, 2003 Author Posted September 27, 2003 Alan, I checked my server environment using "env.pl" and "phpinfo.php" php scripts and they said that GD support is enabled. It said it is version 2.0.12 GD compatible. It also said that "png" support was enabled. Thanks for the "GD.pm" link. I downloaded it, but I am wondering if I even need to install it since GD is already installed on the system. One thing I did notice, but I do not know if it matters, is that the server variable "HTTP_REFERER" is blank (empty). I modified a php script called "acevars.php" to display server data for my site. I added the displaying of the server variable "HTTP_REFERER" and it showed nothing. As mentioned before, in the script "gd-count.cgi" there is a check of this server variable against the "@allowed" variable which I changed (found at the top of the script) to list my website. So maybe the "HTTP_REFERER" has to be "turned-on" so that the "gd-count.cgi" script will recognize it and not exit the script right away. I have no idea how to turn this server variable "on" or if it always is blank for security reasons. Mark Quote
Guest schussat Posted September 27, 2003 Posted September 27, 2003 Well Mark, I'm stumped. I downloaded bscount and played around with it, and I couldn't get past the premature end of header errors, either. I thought I was getting somewhere when I copied GD.pm into the bscount directory, but that didn't quite do it. When I ran bscount as a SSI, I didn't get errors, but I didn't get graphical output, either. Maybe that's the way to do it -- at least as a server-side include, it seems to function, if only marginally. From there, maybe you can debug further? -Alan Quote
markc Posted September 27, 2003 Author Posted September 27, 2003 Alan, Thanks again for your help. I emailed (is emailed an actual word?) the author of the program and he is looking into it. How did you get it to work as a server side include? Did you just name your "index.html" file as "index.shtml"? I know you had to use the count.cgi version of the counter. Where did you put the images folder? In the bscounter folder or did you use the existing images folder - the one found in your public_html folder? I may have to go the ssi route. I thought that I had tried it and it too did not work. I may re-try it. Mark Quote
Guest schussat Posted September 28, 2003 Posted September 28, 2003 How did you get it to work as a server side include? Did you just name your "index.html" file as "index.shtml"? I know you had to use the count.cgi version of the counter. Where did you put the images folder? In the bscounter folder or did you use the existing images folder - the one found in your public_html folder? Yep, that's exactly what I did: I used setup.cgi to generate the SSI syntax, and then simply copied the command (which does use count.cgi in this case) into index.shtml. I tested it with the image files both in the cgi-bin/bscounter directory and in public_html/images -- no love, either way. I'll be interested to hear if the author finds a solution. I know it's been a while since I worked with this stuff, but I'm surprised that between the two of us we haven't tinkered our way to a solution. I mean to mention last time, regarding the http_referer variable: I think it's probably appropriate that it's showing up as empty, because technically there is no referrer. You're loading it straightaway, without a link from some other page. If you set up a second page with a link to that acevars script, I bet the referer field will show the filename then. Best- -Alan Quote
markc Posted September 28, 2003 Author Posted September 28, 2003 Alan, The author of the bscounter is still working on it. Thanks for the confirmation on how to set up the SSI version. You are probably right about the HTTP_REFERER variable being blank. Because I did not come from a linked page I just typed in the URL address. The problem must be something really simple that is being overlooked. Still working on it. Thanks again for your help. Mark Quote
markc Posted October 1, 2003 Author Posted October 1, 2003 Alan and anyone else, Success (with one of the scripts)! Thumbs Up The author of BScounter was nice enough to try and fiqure out what was wrong with my script - gd-count.cgi. He said he could not reproduce my problem but he was able to see the counter numbers on his computer system and browser using the gd-count.cgi script on my server. See the file at: http://www.mectjv.com/cgi-bin/bscounter/test.html. When I viewed this test.html file all I got was a broken image. In my server error log it would only say "premature end of script headers". I use a Mac running Mac OS 10.2.6. I also use Netscape 7.1. So I also tried viewing the test.html file with MS Internet Explorer for Mac and I got the same thing. I then tried viewing the test.html file on my wife's IBM notebook running Windows 2000 and Internet Explorer for Windows. I was able to see the blue counter numbers with that system. So I thought it might be Mac or a Netscape problem. I then decided to try working with the SSI version - count.cgi of the Perl script. When I ran this script, on my browser page I got double quotes surrounding non-graphic numbers. Not the pgn image numbers I am suppose to see. I noticed in my server error log that the file name for the digit image number did not exist. Here is an example of the server error log message: File does not exist: /home/mectjvc/public_html/"/images/digits/plain_b/1.png" File does not exist: /home/mectjvc/public_html/"/images/digits/plain_b/0.png" File does not exist: /home/mectjvc/public_html/"/images/digits/plain_b/1.png" File does not exist: /home/mectjvc/public_html/"/images/digits/plain_b/0.png" I noticed the double quote in front of the /images and also at the end of .png. So I looked in my Perl book and it described another way to quote a string (or expression) using interpolation. It said to use qq( ). The Perl interpetor must add quotes when it serves the page back to the browser. Using the qq( ) is the same as using \" (backward slash quote). I made two changes to the Perl count.cgi script and the Perl interpetor liked using qq( ) instead of \". So I checked it on my Mac / Netscape system and my wife's Windows 2000 IE system and it works. To see it in action go to: http://mectjv.com/index.html. This is just a work-in-progress webpage that uses the count.cgi script (It's not done!). In the Perl script count.cgi I changed two lines: 1. Original count.cgi: >my $digits_dir = "/images/digits/"; To my version: (I only took off the "/" found in front of the word: images) >my $digits_dir = "images/digits/"; 2. Original count.cgi: >print "<img src=\"$digits_dir$style/$num.$imgtype\" alt=\"$num\" />"; To my version: (took off the outside double quotes and added: qq( ) ) >print qq(<img src=\"$digits_dir$style/$num.$imgtype\" alt=\"$num\" />); It now works and it creates stats. I did not try making changes to the Perl script - gd-count.cgi, but it might work for that script to use the qq( ). I read in my Perl book that if the quoted string (expression) uses parentheses, then you have to backslash each parentheses. I know this may seem stupid to spend so much time trying to get a counter on a web page. But I wanted to learn what was wrong and in the process learn about Perl, HTML, cgi's, etc. And sometimes you just get determined to not let things beat you. It comes from my old programming days (Fortran, Cobol, CICS, DB2, etc.). Alan - Thanks again for taking the time to try and debug my script problem. Mark Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.