Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CGI scripting - email 1

Status
Not open for further replies.

JennyW

Technical User
Mar 1, 2001
323
CA
Hieee!

I was wondering if someone could direct me to some good help.

I want to use a ‘lil CGI scripting on my webpage.
Actually, all I want to do is have a button where people can submit their email address to me.

Is this difficult to do?
Where can I get straight-forward info. on how to do this?

Thanks so much for reading!
Jenny
 
nearly trivial....

# an html file with an email input.
Code:
<HTML>
<HEAD><TITLE>Most Basic CGI Input Page</TITLE></HEAD>
<BODY>
<FORM ACTION=&quot;/cgi-bin/getAddress.cgi&quot; METHOD=&quot;POST&quot;>
<P>email address, please: 
<INPUT TYPE=&quot;TEXT&quot; WIDTH=&quot;25&quot; NAME=&quot;E_ADD&quot;>
</P></FORM>
</BODY>
</HTML>
# piece of cgi to catch and write the new email address to a file.
# save this as 'getAddress.cgi' in your cgi-bin dir
Code:
#!/usr/local/bin/perl
use CGI;
$q = new CGI;
print $q->header;
print $q->start_html;
$email = $q->param('E_ADD');

# check to see if the input appears to be an email address
# you should always check your inputs to exclude potentially dangerous stuff.
# this is a minimal attempt at doing that.
unless ($email =~ /.*@.*\.\w+/) { &killme(&quot;Not a valid email address&quot;); }
print &quot;<P>Email is $email</P>\n&quot;;

# open a file named 'emails' in the current dir to append new addresses
unless (open(OPF,&quot;>>emails&quot;)) {&killme(&quot;Failed to open emails file. $!&quot;);}
print OPF &quot;$email\n&quot;;
close OPF;
print $q->end_html;

sub killme
{
print &quot;<P>$_[0]</P>&quot;;
print $q->end_html;
die;
}

I hope this helps... Let me know if you have questions.

If you use this, be aware that


keep the rudder amid ship and beware the odd typo
 
Hi goboating,

Thanks for your help!
This is all pretty new to me. I'm not that versed with cgi.
I have a few questions...

If my host ( supports cgi or perl, which one should I use?

I still have to learn how to import the data you kindly gave me.

When you write...

&quot;you should always check your inputs to exclude potentially dangerous stuff&quot;

...where can I find info. on what else to add to the script so visitors don't mess with me and send me junk?

Thanks for your time, I really do appreciate it!
Jenny
 
&quot;supports cgi or perl&quot; - this is a little confused. There can not be an 'or' relationship between cgi and perl. Perl is a programming language. CGI is a set of rules that you follow to ask a web server to run a program for you. You can use Perl to write CGI code. You can also write CGI with C or Java or.... or.... or any other language with which you can follow the CGI rules. As it turns out, Perl is the most popular language for doing CGI stuff. So, use Perl to write CGI code.


&quot;dangerous stuff&quot; - when you accept input from a user and then use that input in your code, you must be careful. If you accept input from a user that has a command or some other harmful content in it, and you include that input in a system call, you are telling the system to run whatever the user just asked for. I hate to do this to you. But, if you are going to start writing CGI, then you need to read this web security FAQ - See section 6. Some of it may be over your head for a little while, but, I'd start paying attention to the fact that loosely written CGI code can open your server up to attack. Read the FAQ.

Also, you might check out
I hope this helps.




keep the rudder amid ship and beware the odd typo
 
Hi go Boating.
Thanks for the links and the help!

I'm guessing that the code shared with me above is loosely written?

The current host I have doesn't give me the ability to write CGI scripts.

Is there anyway I can practice using cgi? If so how?

Thanks again,
Jenny
 
I'm guessing that the code shared with me above is loosely written?
The code above is not bad. But, I expect you would need to expand it, modify it, and/or tweak it to get it to do exactly what you want it to do. In that tweaking, you might open small holes into large holes...... then it might not be 'not bad' anymore.

Is there anyway I can practice using cgi? If so how?
There are a number of hosting companies that will give you free space. However, I would suggest against that. Better, to setup your own web server-> Download Apache and install it on your box. Yes, this will take a little more learning and a few more posts in Tek-Tips, but, you would end up with a good understanding of CGI from the ground up. And, it is not that hard.....Just follow the directions. The Apache setup is pretty straight forward. Once that is done, you will have a full blown web server available to do what ever you want, including hosting web pages, if you have a static IP (DSL or the like).

I don't know why you are having trouble with that link. I go to the O'Reilly page, just like I should, when I click it. An alternative is to go to and scroll to the bottom section. There is a sub section 'Learning Perl' with a link to tutorials.

HTH


keep the rudder amid ship and beware the odd typo
 
Hey goboating,

What does HTH mean?

It sounds like it would be a very long process to get my own webserver up and running.
You are saying that it’s easy to have make my own server with the Apache software?

All I really want to do is just have a form where visitors can send me their email address (and possibly their comments).

Jenny
 
HTH -> [red]H[/red]ope [red]T[/red]his [red]H[/red]elps... ;-)

'EASY' may be slightly overstating the ease of setup, but only slightly. I really strongly encourage you to try. It has been a while since I played with Apache on a Win OS, but, I think Apache.org has &quot;download and double click to install&quot; versions for Windows (.msi files). The download and install is easy. You can get a good web server running on your local box quickly. Then you can learn to play any CGI games you want.

See
They say in that page that their support for Windows is 'experimental'. However, I have it on my Win98 box at home to use for developing software and I have not had any problems, (other than the normal M$ OS problems). I would not run a public accessible server from a Win OS, but, it is fine for learning how it works and writing CGI. I think it would allow you to learn what CGI is and does in the relative security/anonimity of your own system.


keep the rudder amid ship and beware the odd typo
 
Hi goBoating,
Thanks so much for your help!
I really appreciate it!
Jenny
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top