homepage Welcome to WebmasterWorld Guest from 54.237.125.89
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

    
server-side script
Plum




msg:3312601
 4:09 pm on Apr 16, 2007 (gmt 0)

I would like to get some direction in using cgi and perl. I have an html input form to post to our website.
THe script i believe needs to save the inputted data in a file.

 

Dabrowski




msg:3312671
 5:01 pm on Apr 16, 2007 (gmt 0)

I'm assuming you already know Perl, otherwise I would certainly learn it before attempting to use it on a server.

Anyway, patronising over...

If your form uses method='GET' then parameters will be stored in $ENV{QUERY_STRING}, in the format firstname=John&lastname=Doe&display=Doe%2C+John (same as you see in URL's).

If your form uses method='POST' then input will be stored in a string in the same format, but fed into STDIN instead. The length is $ENV{CONTENT_LENGTH} bytes, so read( STDIN, $postData, $ENV{CONTENT_LENGTH}).

You'll need to unescape the output, and also change '+' into ' '.

perl_diver




msg:3312946
 9:52 pm on Apr 16, 2007 (gmt 0)

I recommend you use the CGI module for parsing all form data (GET, POST, etc) if using perl. Trying to do it manually will just open you up to security issues.

Dabrowski




msg:3312954
 10:05 pm on Apr 16, 2007 (gmt 0)

Please advise perl_diver? I always thought it was my choice what I did with the form input.

perl_diver




msg:3312977
 10:39 pm on Apr 16, 2007 (gmt 0)

The CGI module is the standard for processing form data with perl, has been for many years now. But it is your choice, you can write your own code to process form data if you want to or need to for some reason.

phranque




msg:3312985
 10:47 pm on Apr 16, 2007 (gmt 0)

i would second p_d's recommendation here.
you have nothing to lose by using CGI.pm and little to gain by doing it yourself.

Dabrowski




msg:3312994
 10:59 pm on Apr 16, 2007 (gmt 0)

Due to the number of hits on my server, I try to keep code size to a minimum. I'd rather have a couple of lines of my own code, than a whole module of somebody elses. I realise it's a lot more function than just the form processing. Plus, I know it's reinventing the wheel but you don't learn by using other people's code, I often try to write my own version of some things if I feel I can learn from it.

I have used it on occasion as I can't work out how to process multipart forms for file uploads.

As you said, personal preference, but either way works.

perl_diver




msg:3312995
 10:59 pm on Apr 16, 2007 (gmt 0)

You may find this discussion informative too:

[perlmonks.org...]

perl_diver




msg:3313011
 11:13 pm on Apr 16, 2007 (gmt 0)

the CGI module only loads the functions you need, there is no need to load up the entire module. If you only want to use it for form processing (which is all I use it for in general) just load up the cgi functions/methods.

use CGI qw/:cgi/;

Dabrowski




msg:3313014
 11:17 pm on Apr 16, 2007 (gmt 0)

Thanks for that link, I didn't know about the null byte thing, but I have no intention of letting end users near anything even remotely systemy, let alone my shell.

I couldn't get the article about file uploads unfortunately, it 404ed.

Thanks again for the info.

Back to the point though, Plum please let us know how you get on.

perl_diver




msg:3313015
 11:19 pm on Apr 16, 2007 (gmt 0)

>> Plus, I know it's reinventing the wheel but you don't learn by using other people's code,

You are right, but if you look at the source code of the CGI module (or other modules) I'll bet you can learn a thing or two and incorporate that into your own code. Like how to parse multi-valued form fields:


'SplitParam' => <<'END_OF_FUNC',
sub SplitParam {
my ($param) = @_;
my (@params) = split ("\0", $param);
return (wantarray? @params : $params[0]);
}
END_OF_FUNC

Plum




msg:3313841
 7:54 pm on Apr 17, 2007 (gmt 0)

Thank you for the info from all you people. I was able to complete my project w/out having to use server-side scripting. It did motivate me to expand my knowledge so i will be learning a scripting language.

again thanks everyone

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved