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:
Perl beginner - I need help please

 

First page Previous page 1 2 3 4 5 Next page Last page  View All


JennyW
journeyman

May 16, 2001, 10:19 AM

Post #1 of 123 (10686 views)
Perl beginner - I need help please Can't Post

Hi,
I’m a VERY new beginner.

I have Perl and Apache on my computer.
I want to start testing CGI scripts for my website, but I don’t know where to go from here.

In order to get Apache to run a CGI script I was told to add ExecCGI to the “Options” line in the httpd.conf file.

I added it, then I made a script called, simple.cgi. I tested the script in IE at the http://127.0.0.1/cgi-bin/simple.cgi address, but I got the “Connection Refused” window.

Does anyone know what I’m doing wrong?

Thanks for your time,
Jenny




Kanji
User / Moderator

May 16, 2001, 4:02 PM

Post #2 of 123 (10677 views)
Re: Perl beginner - I need help please [In reply to] Can't Post

"Connection refused" sounds like you either have a firewall/web proxy in place, or your copy of Apache isn't running.



JennyW
journeyman

May 16, 2001, 4:46 PM

Post #3 of 123 (10671 views)
Re: Perl beginner - I need help please [In reply to] Can't Post

Hi Kanji,
Thanks for responding.
My Apache is running and I DON'T have a Firewall. What else could it be?

Maybe my CGI script?

Here's my script...

#!c:/perl/bin/bin
print "Content-type: text/html\n\n";
print "Not Hello, again!\n";

It's in the CGI-bin (within Apache).

Any help is appreciated.

Thanks,
Jenny



Kanji
User / Moderator

May 16, 2001, 4:55 PM

Post #4 of 123 (10669 views)
Re: Perl beginner - I need help please [In reply to] Can't Post

I don't think it's your script.

Have you looked in your Apache logs to see if you really are connecting?




JennyW
journeyman

May 16, 2001, 4:59 PM

Post #5 of 123 (10668 views)
Re: Perl beginner - I need help please [In reply to] Can't Post

Hiee!
Well, the Apache window is open and displays...

Apache/1.3.19 <Win32> running...

How can I check the Apache logs to see if I'm connected? What are Apache logs?

Thanks,
Jenny



Kanji
User / Moderator

May 16, 2001, 6:16 PM

Post #6 of 123 (10665 views)
Re: Perl beginner - I need help please [In reply to] Can't Post

Apache logs keep track of which pages have been served, when, and to whom.

Usually, they are located inside the logs/ subdirectory found wherever you installed Apache and called access.log.



JennyW
journeyman

May 16, 2001, 6:35 PM

Post #7 of 123 (10663 views)
Re: Perl beginner - I need help please [In reply to] Can't Post

Hi Kanji.

Here's what my logs display in Notepad...

access.log


127.0.0.1 - - [13/May/2001:18:29:57 -0400] "GET / HTTP/1.1" 200 1354
127.0.0.1 - - [13/May/2001:18:29:58 -0400] "GET /apache_pb.gif HTTP/1.1" 200 2326
127.0.0.1 - - [13/May/2001:18:31:31 -0400] "GET /manual/ HTTP/1.1" 200 5740
127.0.0.1 - - [13/May/2001:18:31:31 -0400] "GET /manual/images/apache_header.gif HTTP/1.1" 200 4084
127.0.0.1 - - [13/May/2001:18:31:31 -0400] "GET /manual/images/pixel.gif HTTP/1.1" 200 61
127.0.0.1 - - [13/May/2001:18:34:03 -0400] "GET / HTTP/1.1" 200 1354
127.0.0.1 - - [13/May/2001:18:52:14 -0400] "GET / HTTP/1.1" 200 1354
127.0.0.1 - - [13/May/2001:21:59:00 -0400] "GET / HTTP/1.1" 200 1354
127.0.0.1 - - [13/May/2001:21:59:00 -0400] "GET /apache_pb.gif HTTP/1.1" 304 -
127.0.0.1 - - [14/May/2001:20:44:28 -0400] "GET / HTTP/1.1" 200 1354
127.0.0.1 - - [14/May/2001:20:44:28 -0400] "GET /apache_pb.gif HTTP/1.1" 304 -
127.0.0.1 - - [14/May/2001:20:45:20 -0400] "GET /cgi-bin/ScriptName HTTP/1.1" 404 312
127.0.0.1 - - [14/May/2001:20:45:39 -0400] "GET /cgi-bin/printenv.pl HTTP/1.1" 500 634
127.0.0.1 - - [14/May/2001:20:46:37 -0400] "GET /cgi-bin/first HTTP/1.1" 404 307
127.0.0.1 - - [15/May/2001:18:20:05 -0400] "GET /cgi-bin/simple.cgi HTTP/1.1" 404 312
127.0.0.1 - - [15/May/2001:18:42:45 -0400] "GET / HTTP/1.1" 200 1354
127.0.0.1 - - [15/May/2001:18:42:46 -0400] "GET /apache_pb.gif HTTP/1.1" 304 -
127.0.0.1 - - [15/May/2001:18:43:29 -0400] "GET /cgi-bin/simple.cgi HTTP/1.1" 500 634
127.0.0.1 - - [15/May/2001:22:04:15 -0400] "GET /cgi-bin/simple.cgi HTTP/1.1" 500 634
127.0.0.1 - - [16/May/2001:20:27:53 -0400] "GET / HTTP/1.1" 200 1354
127.0.0.1 - - [16/May/2001:20:27:53 -0400] "GET /apache_pb.gif HTTP/1.1" 304 -
127.0.0.1 - - [16/May/2001:20:30:06 -0400] "GET / HTTP/1.1" 200 1354
127.0.0.1 - - [16/May/2001:20:30:34 -0400] "GET /cgi-bin/simple.cgi HTTP/1.0" 500 622


error.log

Apache server shutdown initiated...
Apache server shutdown initiated...
[Mon May 14 20:45:20 2001] [error] [client 127.0.0.1] (2)No such file or directory: script not found or unable to stat: c:/program files/apache group/apache/cgi-bin/scriptname
[Mon May 14 20:45:39 2001] [error] [client 127.0.0.1] couldn't spawn child process: c:/program files/apache group/apache/cgi-bin/printenv.pl
[Mon May 14 20:46:37 2001] [error] [client 127.0.0.1] (2)No such file or directory: script not found or unable to stat: c:/program files/apache group/apache/cgi-bin/first
[Tue May 15 18:20:05 2001] [error] [client 127.0.0.1] (2)No such file or directory: script not found or unable to stat: c:/program files/apache group/apache/cgi-bin/simple.cgi
[Tue May 15 18:43:29 2001] [error] [client 127.0.0.1] couldn't spawn child process: c:/program files/apache group/apache/cgi-bin/simple.cgi
[Tue May 15 22:04:15 2001] [error] [client 127.0.0.1] couldn't spawn child process: c:/program files/apache group/apache/cgi-bin/simple.cgi
[Wed May 16 20:30:34 2001] [error] [client 127.0.0.1] couldn't spawn child process: c:/program files/apache group/apache/cgi-bin/simple.cgi


Does this tell you anything?

Could the problem lie within my Perl installation? How can I check if perl is OK?

Thanks,
Jenny





Cure
User

May 16, 2001, 7:48 PM

Post #8 of 123 (10660 views)
Re: Perl beginner - I need help please [In reply to] Can't Post

Options Indexes FollowSymLinks MultiViews
Options All ExecCGI


Cure



mhx
Enthusiast / Moderator

May 16, 2001, 11:08 PM

Post #9 of 123 (10655 views)
Re: Perl beginner - I need help please [In reply to] Can't Post

Hi Jenny!

Just a guess, but perhaps it helps. I think I've encountered the same error when I was first running Perl/Apache under Windows. My problem was the shebang line in the cgi-script. Apache needs to know the exact location of your perl interpreter. For me, it was

C:\Programme\perl\bin\perl.exe

so I had to put

#!C:\Programme\perl\bin\perl.exe

as the first line of my cgi-script. Anything else doesn't work. While the script may run perfectly if it is started directly, it will not work when Apache is trying to start it.
(This can be quite annoying if you develop a script using a Windows installation and upload the script on a UNIX server, because it just won't work unless you change the shebang-line...)

Hope this helps.

-- Marcus



JennyW
journeyman

May 17, 2001, 6:23 AM

Post #10 of 123 (10646 views)
Re: Perl beginner - I need help please [In reply to] Can't Post

Hiee Marcus!

I heard you have to take out the .exe extension on perl.exe?

You wrote…
Anything else doesn't work. While the script may run perfectly if it is started directly, it will not work when Apache is trying to start it.

What do you mean here?

You also wrote…
(This can be quite annoying if you develop a script using a Windows installation and upload the script on a UNIX server, because it just won't work unless you change the shebang-line...)

How would I change the shebang line?

Also,

You wrote that my shebang line should look like this…

#!C:\Programme\perl\bin\perl.exe

My path is the same. However, I have a few questions.

1. Instead of “Programme” I have Program Files. How are spaces treated (the space between Program Files)?
2. Does the C: and Program Files have to be capitalized?

Thanks so much,
Jenny




mhx
Enthusiast / Moderator

May 17, 2001, 12:50 PM

Post #11 of 123 (10639 views)
Re: Perl beginner - I need help please [In reply to] Can't Post

Hi Jenny!

> I heard you have to take out the .exe extension on perl.exe?

It doesn't matter if you take it out or leave it, at least on my machine.

>You wrote…
>Anything else doesn't work. While the script may run perfectly if it is started directly, it will not work when Apache is trying to start it.
>What do you mean here?

You can start (most) cgi-scripts from with the Perl interpreter directly from the command line. You don't get the HTML content displayed in your browser, but only printed in your command window. Under Windows, the shebang line is not of importance, except for the options you pass to the interpreter.
Under Unix, it is used to determine the location of your interpreter. Apache also uses the line to determine the location of the interpreter under Windows.

> How would I change the shebang line?

I'm not quite sure what you want to know here ;-)
You can just edit the line (?). Under Unix, the shebang line normally looks like


Code
#!/usr/local/bin/perl

Since I'm also testing my scripts under Windows, but my server is running Unix, I've written an upload script that not only uploads all new or modified files automatically, but also changes the shebang line of all cgi-scripts temporarily when uploading.
I hope the answer you expected is somewhere in between...

> 1. Instead of “Programme” I have Program Files. How are spaces treated (the space between Program Files)?

That seems to be a problem. (I guess the german version of Windows has a slight advantage here...) I've tried to get my script running with spaces in the path, but it didn't work. I'd recommend that you install Perl in another folder, say 'c:\bin\', as I do when I'm working with the english version.

> 2. Does the C: and Program Files have to be capitalized?

No, they don't. Unlike Unix, Windows isn't case sensitive here.

I hope all this makes the situation a bit clearer.

Greetings,
Marcus



JennyW
journeyman

May 18, 2001, 4:12 PM

Post #12 of 123 (10621 views)
Re: Perl beginner - I need help please [In reply to] Can't Post

Success!

Here’s the script that worked for me...

#!c:/perl/bin/bin/perl
print "Content-type: text/html\n\n";
print "Not Hello, again!\n";

My main and most recent problem was my incorrect path in my shebang line, but it’s ok now. Thanks.
Does my shebang line need to be like that for every script I have? Will my shebang line be different if I'm posting a .cgi script to a webhost’s server?

I have a few more important questions…

The script above was named simple.cgi

When I tested my script I was successful using the following url in both Netscape and IE…
http://localhost/cgi-bin/simple.cgi

However, my test only worked for Netscape under this url…
http://127.0.0.1/cgi-bin/simple.cgi

When I entered the above url in IE I received this message...

Connection refused
Description: Connection refused

Is this a problem? Why did this happen only for the http://127.0.0.1/cgi-bin/simple.cgi address on Internet Explorer?

What the difference between the localhost and the 127.0.0.1 extension?

And finally…

What do I open when I want to test scripts directly in perl?
Do I open (double click) perl.exe ?

What would be the point of testing scripts directly in perl?

Thanks so much for taking the time,
Jenny





mhx
Enthusiast / Moderator

May 18, 2001, 11:26 PM

Post #13 of 123 (10609 views)
Re: Perl beginner - I need help please [In reply to] Can't Post

Hi Jenny!

> Does my shebang line need to be like that for every script I have?

On your machine, as long as the Perl interpreter does not move, yes. Except I would generally recommend to append a '-w' to the shebang line to make Perl issue some warnings. This generally leads to better Perl code and fewer / easier to find errors.

> Will my shebang line be different if I'm posting a .cgi script to a webhost’s server?

I think so. I've not seen a webserver yet having perl installed in 'c:/perl/bin/bin/perl'. Since most webservers I know about run Unix or Linux, your shebang line should most likely be


Code
#!/usr/local/bin/perl -w

But most webspace providers with cgi support list on their page where perl and sendmail are installed.

> When I tested my script I was successful using the following url in both Netscape and IE
> http://localhost/cgi-bin/simple.cgi
> However, my test only worked for Netscape under this url
> http://127.0.0.1/cgi-bin/simple.cgi
> When I entered the above url in IE I received this message...
> Connection refused
> Description: Connection refused
> Is this a problem?

I don't think so. At least I don't think it's your problem. Perhaps it's your version of IE, although I really can't imagine why it would work the one way, but not the other. I've tried to reproduce this on my machine, but my IE (Version 5.00.2919.6307IC) worked with both URLs.

> Why did this happen only for the http://127.0.0.1/cgi-bin/simple.cgi address on Internet Explorer?

I can't tell you, really. Perhaps you can get some more information from Apache's server logs.

> What the difference between the localhost and the 127.0.0.1 extension?

There should be none. Here's what the Apache config file says:

# 127.0.0.1 is the TCP/IP local loop-back address, often named localhost. Your
# machine always knows itself by this address. If you use Apache strictly for
# local testing and development, you may use 127.0.0.1 as the server name.

BTW, there was another interesting thing in the config file:

# Apache parses all CGI scripts for the shebang line by default.
# This comment line, the first line of the script, consists of the symbols
# pound (#) and exclamation (!) followed by the path of the program that
# can execute this specific script. For a perl script, with perl.exe in
# the C:\Program Files\Perl directory, the shebang line should be:

#!c:/program files/perl/perl

# Note you _must_not_ indent the actual shebang line, and it must be the
# first line of the file. Of course, CGI processing must be enabled by
# the appropriate ScriptAlias or Options ExecCGI directives for the files
# or directory in question.

I guess, reading the complete config file could be quite useful for me... Smile

> And finally
> What do I open when I want to test scripts directly in perl?
> Do I open (double click) perl.exe ?
No, you open a command prompt, change to the directory your scripts are in, and run the script with

Code
perl simple.cgi

> What would be the point of testing scripts directly in perl?
Well, um, I can't see a point right now. When I started writing cgi scripts, I had quite a lot of experience writing Perl scripts.
So I was more familiar with the command line execution of my scripts, and I've been struggling with Apache just as you did Crazy
I only ran cgi scripts directly to trap errors. But there's a better way to do this. Just start every script you write with


Code
#!c:\programme\perl\bin\perl.exe -w 
use CGI::Carp qw(fatalsToBrowser);
use CGI qw/:standard/;
use strict;

The CGI::Carp qw(fatalsToBrowser) will make all perl errors appear in your browser window.
The CGI qw/:standard/ will be a great support when you want to generate HTML and parse CGI forms. One should really use this!
The use strict is because I'm a Perl writer. Perl (and CGI) scripts tend to become more readable and error free when using this.

If there's anything else you'd like to know, or you would want in more detail, just ask.

-- Marcus




JennyW
journeyman

May 19, 2001, 10:59 AM

Post #14 of 123 (10600 views)
Re: Perl beginner - I need help please [In reply to] Can't Post

Hi,
Wow, thanks for the great response!

1. You wrote...
#!c:\programme\perl\bin\perl.exe -w
use CGI::Carp qw(fatalsToBrowser);
use CGI qw/:standard/;
use strict;

Should the above be my FIRST four lines in all of my .cgi scripts?

2. I got to the command line, but I could things going.
I would type…

cd\program files

…but it wouldn’t recognize my request. It would say…Too many parameters – files

Is it because…

Program Files

…has a space in between it?

Do you know how I can get through this is DOS?

3. You quoted the httpd.conf with the following…

# Apache parses all CGI scripts for the shebang line by default.

What does the above mean?

Thanks so much for taking the time,
Jenny




mhx
Enthusiast / Moderator

May 19, 2001, 1:32 PM

Post #15 of 123 (10598 views)
Re: Perl beginner - I need help please [In reply to] Can't Post

Hi Jenny,

> Should the above be my FIRST four lines in all of my .cgi scripts?

Well, more or less yes. I strongly recommend 'use strict', because it forces a clean programming style. The two CGI modules are very useful for CGI programming. IMO far too less people are using it and mess around i.e. with parsing for CGI parameters. The shebang line is of course mandatory and must be the first. The others should appear somewhere on top of your script. If you include any other modules, put them before, somewhere in between, whatever you like. It's not of importance, as long as all this appears on top of your code.

> Is it because Program Files has a space in between it?
> Do you know how I can get through this is DOS?

Yes, it is. You can change to this folder by typing

Code
cd "\program files"

Just quote any directory/file names with spaces in between when using the DOS prompt.

> 3. You quoted the httpd.conf with the following…
> Apache parses all CGI scripts for the shebang line by default.
> What does the above mean?

I just quoted this paragraph because it shows that the path in the shebang line may contain spaces. I don't know why this failed to work on my machine. The above just means that Apache looks at the shebang line to find out where the Perl interpreter is located.

-- Marcus



JennyW
journeyman

May 20, 2001, 2:20 PM

Post #16 of 123 (10583 views)
Re: Perl beginner - I need help please [In reply to] Can't Post

Hi mhx,
You wrote…

Yes, it is. You can change to this folder by typing
cd "\program files"

That worked great! Thanks!

Thanks to your help I’m beginning to test .cgi scripts! However, I need your assistance, because I’m having some trouble.

1. Here’s my html Form…

<HTML>
<HEAD><TITLE>Most Basic CGI Input Page</TITLE></HEAD>
<BODY>
<FORM ACTION="emailtest.cgi" METHOD="POST">
<P>email, please:
<INPUT TYPE="TEXT" WIDTH="25" NAME="Email_Address">
</P></FORM></BODY></HTML>

2. I tested my <html> Form with the following .cgi code. My results were strange.
(The .cgi script below is suppose to accept any email address and display it on a new page).

By the way, I haven’t used your code yet…

#!c:\programme\perl\bin\perl.exe -w
use CGI::Carp qw(fatalsToBrowser);
use CGI qw/:standard/;
use strict;


I’m definitely going to use this code in the NEAR future. I just wanna get a handle on the basics first. Here’s the .cgi code I used…


#!/usr/local/bin/perl
#
%FORM = &cgidecode();
$email = $FORM{Email_Address};
print "Content-type: text/html\n\n";
print "<HTML><HEAD><TITLE>Catching an email</TITLE></HEAD>\n";
print "<BODY><P>Address is: $email.</P></BODY></HTML>";

sub cgidecode
{
local(%vars, $val, $key, $last, $buffer, $pair, @pairs);
# Checking the form method (GET or POST) used
# in the HTML code. POST method sends data to
# standard input, but GET adds it to the URL
# and stores it in QUERY_STRING.
if ($ENV{'REQUEST_METHOD'} eq "POST")
{ read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); }
else
{ $buffer = $ENV{'QUERY_STRING'}; }

# Splitting up the data fields and store in array @pairs,
# they are seperated with &
@pairs = split(/&/, $buffer);

# Splitting the variable names and the values and storing
# them in the assoc. array %vars
foreach $pair (@pairs)
{
($key, $val) = split(/=/, $pair);
$val =~ s/\+/ /g;
$val =~ s/%(..)/pack("C",hex($1))/eg;
if ($key eq $last) {$vars{$key} .= " ".$val; }
else { $vars{$key} = $val; }
$last = $key;
}
return(%vars);
}



After I entered an email address I was brought to a new screen, which displayed the following…



#!c:/perl/bin/bin/perl # %FORM = &cgidecode(); $email = $FORM{Email_Address}; print "Content-type: text/html\n\n"; print "\n"; print "
Address is: $email.
"; sub cgidecode { local(%vars, $val, $key, $last, $buffer, $pair, @pairs); # Checking the form method (GET or POST) used # in the HTML code. POST method sends data to # standard input, but GET adds it to the URL # and stores it in QUERY_STRING. if ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } else { $buffer = $ENV{'QUERY_STRING'}; } # Splitting up the data fields and store in array @pairs, # they are seperated with & @pairs = split(/&/, $buffer); # Splitting the variable names and the values and storing # them in the assoc. array %vars foreach $pair (@pairs) { ($key, $val) = split(/=/, $pair); $val =~ s/\+/ /g; $val =~ s/%(..)/pack("C",hex($1))/eg; if ($key eq $last) {$vars{$key} .= " ".$val; } else { $vars{$key} = $val; } $last = $key; } return(%vars); }

Do you know what could have happened here?

Thanks,
Jenny




mhx
Enthusiast / Moderator

May 20, 2001, 11:55 PM

Post #17 of 123 (10579 views)
Re: Perl beginner - I need help please [In reply to] Can't Post

Hi Jenny,

I've tested your html/script on my machine. After applying two minor changes, they worked absolutely fine. These changes were:
1. The shebang line wasn't ok for my system
2. I had to change "emailtest.cgi" to "cgi-bin/emailtest.cgi"
I think both changes don't have anything to do with your problem, but only with my configuration.
Now, let's move on to analyze your problem. Did you ever get a cgi-script running with your current configuration? It seems that Apache is finding your cgi script, but doesn't know how to interpret it, so it just sends the script to the browser as plain ascii data. If you've been running scripts with this configuration, I really don't know why it doesn't work. If this is the first script you're trying to run, I guess it could be that your Apache httpd.conf is not properly set up.
You should take a look at this file and see if the "ExecCGI" option is enabled and if there's a line

Code
AddHandler cgi-script .cgi .pl

I'm sorry I can't give you more precise information about this.
Anyway, to convince you of using the CGI modules, I have rewritten the code you posted in a way that uses my first four lines and is - so I guess - more readable and understandable for the beginner. Although it doesn't use a single HTML tag, it contains both, the HTML and the CGI, in one file that is significantly shorter than the two original files. To make a transition easier, this script produces exactly the same output as yours, except it adds a 'Submit' button to the form.

Code
#!c:\programme\perl\bin\perl.exe -w 
use CGI::Carp qw(fatalsToBrowser);
use CGI qw/:standard/;
use strict;

print header;

unless( param() ) # no parameters? => display form!
{
print start_html(-title => "Most Basic CGI Input Page"), start_form;
print "email, please: ", textfield(-size => 25, -name => 'Email_Address');
print submit('Submit'), end_form;
}
else # we have parameters => display results!
{
print start_html(-title => "Catching an email");
print p("Address is: ", param('Email_Address'));
}

print end_html;

I think the script is self-explanatory. If it should not be, ask and I'll explain.

-- Marcus



JennyW
journeyman

May 21, 2001, 12:14 PM

Post #18 of 123 (10572 views)
Re: Perl beginner - I need help please [In reply to] Can't Post

Hi mhx and others!

Ok, to start, yes, I have got the simple script…”Hello World” to work on my machine.

Here’s the code I used for that script…

Code
#!c:/perl/bin/bin/perl 
print "Content-type: text/html\n\n";
print "Hello World!\n";

I just can’t seem to get this script working.

You wrote…

>If this is the first script you're trying to run, I guess it could be that your Apache >httpd.conf is not properly set up.
>You should take a look at this file and see if the "ExecCGI" option is enabled and if >there's a line
>

Code
>AddHandler cgi-script .cgi .pl

My httpd.conf file does have the ExecCGI file enabled, but I’ve never done anything with the…

Code
AddHandler cgi-script .cgi .pl

What is AddHandler? Is it necessary?

I heard when using windows all of my .cgi files should have the .pl extension instead. Is that correct?

Also, I tried running the script you posted, but I couldn’t.
I named the file…


Code
 mhx_email_test.cgi

…and I tried to open it in a browser (IE), but was unsuccessful. Nothing happens when I open it.

Thanks,
Jenny





JennyW
journeyman

May 21, 2001, 12:54 PM

Post #19 of 123 (10572 views)
Re: Perl beginner - I need help please [In reply to] Can't Post

Hi mhx,

Ok, I’m starting to think a little late today.
I got your script working.

I typed the following in the url bar…

Code
http://localhost/cgi-bin/mhx_email_test.cgi

…and your script appeared as did my tested results.

If you can, read the post I wrote before this one. It has a few more questions in it. However, if you don’t have the time then don’t worry about it, you’ve been so good to me.

Thanks,
Jenny




mhx
Enthusiast / Moderator

May 21, 2001, 1:07 PM

Post #20 of 123 (10570 views)
Re: Perl beginner - I need help please [In reply to] Can't Post

Hi Jenny,

> What is AddHandler? Is it necessary?

The AddHandler line tells Apache that files with .pl or .cgi extension are CGI-scripts. So Apache will add a handler for cgi-scripts. Well, I'm not sure if it's really neccessary. If I'd be running my own server, I'd probably know more about Apache ;-)

> I heard when using windows all of my .cgi files should have the .pl extension instead. Is that correct?

Well, I guess not. I think what you heard comes from that fact that the extension .pl is usually associated with Perl under Windows, while .cgi is not. You can configure the Windows version of Apache to use file association from the Windows registry. If you don't have the AddHandler line, then perhaps it will work only with the .pl extension. But, as I said before, I'm no Apache expert. I've installed it, configured it, and now only use it for offline testing of my less than 5 cgi-scripts... I think I'm more into Perl that into web programming. But I try to help where I can.

-- Marcus



JennyW
journeyman

May 22, 2001, 10:07 AM

Post #21 of 123 (10551 views)
Re: Perl beginner - I need help please [In reply to] Can't Post

Hi Marcus :)

I adjusted the Addhandler field in my httpd.conf file. So that’s all set up! Thanks for the info.

As always I have another problem. I’m trying to test a .cgi script, but I’m having a ‘lil trouble.

The .cgi script I’m trying to test allows website visitors to easily email me from an <html> Form.

I highlighted the segments I think I’m making errors on.
Below is only part of the script. To see the whole script go to this link…
http://members.home.net/pie3.14/AlphaMail.txt

In Reply To
#!c:\perl\bin\bin\perl.exe -w
use CGI::Carp qw(fatalsToBrowser);
use CGI qw/:standard/;
use strict;

# URL to go to if there is a problem with form input
$ErrorPage = "a_fail.html";

# URL to go to when form has been successfully submitted
$ThankPage = "a_thanks.html";

# URL to go to if a 'foreign' referer calls the script
$EvilReferer = "http://www.cnn.com";;

# E-mail address to send intake form to (your address)
# If not using PERL 5, escape the @ thus: \@ instead of @
$YourEmail = 'themustache@hotmail.com';

# Script works only on your server(s) - ('URL1','URL2')
@referers = ('www.yoursite.com','yoursite.com');

# Location of mail program - check your doc or ask admin
$MailProgram = '/usr/lib/sendmail';

# Subject of the e-mail autoreply to the submitter
$Subject = "Thanks for Your Message!";

# Header line in the auto-reply message
$Header = "GOOBERS UNLIMITED";

# Brief tail message for body of e-mail autoreply
$TailMessage = "If your message requires a reply, we'll get back to you soon.";

# Your signature lines the end of the autoreply e-mail
$Signature1 = "John Q. Public";
$Signature2 = "www.YourSite.com";;

I’m unsure what to enter in the highlighted segments? Is this where I’m making errors?

Thanks,
Jenny



mhx
Enthusiast / Moderator

May 22, 2001, 11:07 AM

Post #22 of 123 (10550 views)
Re: Perl beginner - I need help please [In reply to] Can't Post

Hi Jenny,

First, kill the 'use strict' line. This script wasn't supposed to run in 'strict' mode, because it doesn't declare its variables. (It's not yours originally, is it?)
Most of the highlighted segments are uncritical.
$ErrorPage and $ThankPage should both point to existing HTML files.
@referers should contain the name of the server where the script resides. If you're testing locally, it's 'localhost'.
$MailProgram is the most important thing. If you have sendmail installed (which I believe you don't have, I don't even know if there's a windows port of it), you must enter the path to sendmail here. For testing, you have to upload the script to your webspace provider and enter the path where he has installed sendmail. First of all, you should check if your provider supports sending mail.

I hope this makes it a bit clearer.

-- Marcus



JennyW
journeyman

May 22, 2001, 11:44 AM

Post #23 of 123 (10548 views)
Re: Perl beginner - I need help please [In reply to] Can't Post

Hi Marcus,
To start, no this script isn’t mine. I got it off a link from this site.

In Reply To
You wrote…
@referers should contain the name of the server where the script resides. If you're testing locally, it's 'localhost'.

So the segment that looks like this…

# Script works only on your server(s) - ('URL1','URL2')
@referers = ('www.yoursite.com','yoursite.com');

Should look like this?

# Script works only on your server(s) - ('URL1','URL2')
@referers = ('http://localhost','yoursite.com');

It’s just plain ‘ol localhost? Not localhost/cgi-bin/fileman.cgi ?

Why does the above say URL1, URL2?


In Reply To
You wrote…

$MailProgram is the most important thing. If you have sendmail installed (which I believe you don't have, I don't even know if there's a windows port of it), you must enter the path to sendmail here. For testing, you have to upload the script to your webspace provider and enter the path where he has installed sendmail. First of all, you should check if your provider supports sending mail.


I don’t have a host right now, that’s why I’m testing on Apache.
What is sendmail?
Do ALL emails sent from a Form require Sendmail?

I’m gonna have to try to see if I can find that Sendmail somewhere.

Thanks,
Jenny



mhx
Enthusiast / Moderator

May 22, 2001, 1:21 PM

Post #24 of 123 (10546 views)
Re: Perl beginner - I need help please [In reply to] Can't Post

Hi Jenny,

> # Script works only on your server(s) - ('URL1','URL2')
> @referers = ('http://localhost','yoursite.com');
> It’s just plain ‘ol localhost? Not localhost/cgi-bin/fileman.cgi ?

I think it's just 'localhost'. But, anyway, I'm not sure if you will be able to get the script to work under Windows.

> I don’t have a host right now, that’s why I’m testing on Apache.

You should try to get a webspace provider. If you don't know any, try www.netfirms.com. Their service is free, and they offer CGI and sendmail support. That's how I'm testing scripts that use sendmail.

> What is sendmail?

sendmail is a (Unix) program to send e-mail. You just feed in a mail in ascii format and sendmail does all the rest.

> Do ALL emails sent from a Form require Sendmail?

Yes. Not actually sendmail, but at least another program that is able to send e-mail and can be controlled from perl.
Here's a script I've assembled to test email sending at www.netfirms.com:

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

print header, start_html(-title => "Send me mail!");

if( param() && param('matter') ) {
my $mymail = 'Marcus Holland <marcus@holland.de>';
my $sender = param('sender') || 'anonymous@nowhere.com';
my $subject = param('subject') || 'no subject';

open SENDMAIL, "| /usr/lib/sendmail -oi -t" or die "cannot open sendmail: $!";
print SENDMAIL "From: $sender\nTo: $mymail\nSubject: $subject\n".param('matter');
close SENDMAIL or die "cannot close sendmail: $!";

print p('Your mail has been sent!');
}
else {
print start_form,
table(Tr([
td([ b('From:'), textfield( -name => 'sender', -size => 35, -maxlength => 100 ) ]),
td([ b('Subject:'), textfield( -name => 'subject', -size => 35, -maxlength => 100 ) ]),
])),
table(Tr([
td([ textarea( -name => 'matter', -rows => 12, -columns => 40 ) ]),
td([ submit('Send!') ]),
])),
end_form;
}

print end_html;

It should work for most providers and doesn't have so much parameters to be configured. But it's only a test.

-- Marcus




JennyW
journeyman

May 23, 2001, 8:45 AM

Post #25 of 123 (10534 views)
Re: Perl beginner - I need help please [In reply to] Can't Post

Hi Marcus!

Thanks for the referral to http://www.netfirms.com ! This is exactly what I needed all along! You’ve made me very happy!

Now, I have a few questions for you.

1.What’s the difference between Formmail and Sendmail?
2.Can I use any email through Sendmail? E.g. hotmail accounts?


In Reply To
Netfirms.com wrote…
Set the file permissions on the cgi script file and directories to be 'chmod 755'.

3.What does this mean? How can I do this?
I read it has something to do with FTP. I use WSFTP.

Most importantly…

A few days ago you supplied me with that email catching .cgi code. I noticed that the html and the .cgi where combined into one document.
See code…

http://members.home.net/pie3.14/email_catching.txt

I think this is a problem for me. I think I need to have a static html page with a Form that calls my .cgi program to send the email.

The reason for this is I want to place my Form on a specific location on my html page.
For example, I want to place my Form where the black box is located on the following page…

http://members.home.net/pie3.14/0013_tek_tips_cgi_help.html

4.Would it be better to have my Form call my .cgi program to send me the mail?

Thanks again and again!
Jenny


First page Previous page 1 2 3 4 5 Next page Last page  View All
 
 


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

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