View Full Version : CGI needed to handle variables from a post url
ClevelandSlim
07-10-2008, 06:04 PM
I need a cgi script to handle a very simple task. What I need is... another company will be sending me variables via a post url. I need the link to be a cgi script on my end with the post varibles after the file.cgi?variable1=...?variable2=...
I need for the cgi to then take the variables and write them to a MySQL database.
I know this should be very easy, EXCEPT... I don't know any cgi.
Where should I start.
Please help.
All the best,
~Slim~
FishMonger
07-10-2008, 07:33 PM
Your starting point would be to learn how to write basic Perl scripts, then learn the basics of the CGI specification.
http://www.w3.org/CGI/
If the variables are being passed in the query string of the url, then it was submitted via the GET method, not the POST method.
In either case, a Perl script would use the same approach to retrieve either method. That approach would be to use the methods provided by CGI module. http://search.cpan.org/~lds/CGI.pm-3.38/CGI.pm
The CGI module provides several methods to retrieve the variables. Here's an example of the most common method I use.
#!/usr/bin/perl
use strict;
use warnings;
use CGI;
my $cgi = CGI->new;
my %params = $cgi->Vars; # this retrieves/places the submitted variables into a hash table.
# you can access individual variables like this:
print $params{'variable1'}, "\n";
print $params{'variable2'}, "\n";
print $params{'variable3'}, "\n";
To enter the submitted data into MySQL you'd use the DBI and DBD::mysql modules.
http://search.cpan.org/~timb/DBI-1.605/DBI.pm
http://search.cpan.org/~capttofu/DBD-mysql-4.007/lib/DBD/mysql.pm
oesxyl
07-10-2008, 11:03 PM
I need a cgi script to handle a very simple task. What I need is... another company will be sending me variables via a post url. I need the link to be a cgi script on my end with the post varibles after the file.cgi?variable1=...?variable2=...
I need for the cgi to then take the variables and write them to a MySQL database.
I know this should be very easy, EXCEPT... I don't know any cgi.
Where should I start.
Please help.
All the best,
~Slim~
FishMonger already give you the answer, I want only to be sure that you are aware that sending data thru the net this way is not safe. I mean, anybody can intercept and/or modify that data.
regards
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.