Forum Moderators: coopster & phranque

Message Too Old, No Replies

Problems with Random Image Script

Newbie over her head

         

Cienwen

7:32 pm on May 30, 2006 (gmt 0)

10+ Year Member



Hello,

I have gotten a random image script and I am trying to adapt it for my needs, being new to perl. So, with respect to the posting guidelines, I am going to try to give enough details without filling this post with all of my script.

First, let me say that I have used this script with another host just the way I have it and it works just fine.

I have set the file permissions to 755. The path to Perl is #!/usr/local/bin/perl as the host has told me. My script ending is .pl

my @images = ({ file => '/Images/welcome/new/lily_bg.jpg',
alt => 'My Site Here' },
{ file => '/Images/welcome/new/mirror.jpg',
alt => 'My Site Here' };

This is how I have linked to my images.

And this is how I am calling the code in my HTML

<!--#include virtual="cgi-bin/random.pl" -->

Just to be safe I have named the file with the .shtml extension.

Nonetheless, every time I try to run the script I get this error message were my image should be, [an error occurred while processing this directive]

This script has worked for me on every other website I have used it on except this one. I have asked my host to check it out and they say it is my problem and I am out of luck.

Can anyone give me a hint as to what is going on here. If you need more info I would be happy to provide it.

Thank you in advance,
Cienwen

milanmk

8:26 pm on May 30, 2006 (gmt 0)

10+ Year Member



Did you check your server error logs? What does it shows?

Milan

KevinADC

9:37 pm on May 30, 2006 (gmt 0)

10+ Year Member



try using the full url to the script in your SSI tag and see if that helps:

<!--#include virtual="http://www.yoursite.com/cgi-bin/random.pl" -->

the perl code you posted is not valid syntax but maybe that's just a copy/paste error, it's missing the right parenthesis ')' at the end of the array assignment:


my @images = (
{file => '/Images/welcome/new/lily_bg.jpg',
alt => 'My Site Here' },
{file => '/Images/welcome/new/mirror.jpg',
alt => 'My Site Here' }
); #<-- this is missing in your code;

milanmk

10:40 pm on May 30, 2006 (gmt 0)

10+ Year Member



try using the full url to the script in your SSI tag and see if that helps:
<!--#include virtual="http://www.yoursite.com/cgi-bin/random.pl" -->

The URL cannot contain a hostname, only a path and an optional query string.

Milan

KevinADC

11:13 pm on May 30, 2006 (gmt 0)

10+ Year Member



ahh, yes, the path should be relative to the folder the .shtml document is in. Thanks for pointing that out.

Cienwen

1:19 am on May 31, 2006 (gmt 0)

10+ Year Member



Thank you all for your relpies. Yes, I do have the ')' included.

This is the error log. Maybe someone can make sense of it.

[Tue May 30 18:06:32 2006] [error] [client ######] unable to include "cgi-bin/random.pl" in parsed file /home/username/public_html/welcome02.shtml
[Tue May 30 18:06:32 2006] [error] [client ######] Premature end of script headers: /home/username/public_html/cgi-bin/random.pl fopen: Permission denied failed to open log file
[Tue May 30 18:02:57 2006] [error] [client ######] unable to include "cgi-bin/random.pl" in parsed file /home/username/public_html/welcome02.shtml
[Tue May 30 18:02:57 2006] [error] [client ######] Premature end of script headers: /home/username/public_html/cgi-bin/random.pl fopen: Permission denied failed to open log file

milanmk

4:21 am on May 31, 2006 (gmt 0)

10+ Year Member



Try to explicitly relax the permissions for SSI by adding Options Includes in your .htaccess file and see if it works.

Milan

rainborick

2:03 pm on May 31, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



"Premature end of script headers" has four common causes:

(1) The script file was not uploaded in ASCII format. Be sure to use Notepad or other simple text file editor to edit your Perl scripts and be sure your FTP program is set to upload in ASCII format. Do not use WordPad or other word processors on Perl scripts.

(2) There is a syntax error in the script itself. Simple explaination, but often the most frustrating and difficult to correct. Start with the possible error a previous poster mentioned here.

(3) If running on an Apache-based server, the script must begin any output with a proper header that includes the MIME-type, as in "Content-type: text/html\n\n".

(4) If running in a Unix/Linux/*nix environment, the permissions setting for either the script file itself or the folder where it resides does not have "Execute" permission. Make sure the permission setting on the script file is 755 with the CHGMOD command. Many FTP programs have this function built-in. I know you mentioned this already, but check it again. Some hosts reset the permissions setting every time you upload a new version of a script.

KevinADC

5:29 pm on May 31, 2006 (gmt 0)

10+ Year Member



I'm also suspecting not uploaded in ASCII format, because the OP says this same script has worked on other severs.

Cienwen

9:14 pm on May 31, 2006 (gmt 0)

10+ Year Member



Thank you all for your help.

The simplest answer was the right one. I had a syntax error and it took FOREVER to find. Everything is working now.

Thank you again.

WebmasterWorld rocks!

MichaelBluejay

11:03 pm on Jun 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



For future reference, put this at the top of your scripts, right under the shebang line:

use CGI::Carp qw/fatalsToBrowser/;

Then, instead of printing "An error occurred while processing this directive", instead you'll get a *specific* description of the error. I couldn't live without this.