Passing value pairs

Posted on 1999-01-12
Medium Priority
Last Modified: 2013-12-25
our customers, after payinging, end up at a page with the code below, then they click on the submit button on the page:


<body bgcolor="#FFFFFF">


<table width="600">

<tr><td colspan="2"> rcpt header




<td align="center" colspan="2">

<form method="POST" action="http://www.mydomain.com/cgi-bin/myscript.cgi">

<input type="hidden" name="INVOICE" value="1001">

<input type="hidden" name="DESCRIPTION" value="">

<input type="hidden" name="AMOUNT" value="$1.00">

<input type="hidden" name="CUSTID" value="4">

<input type="hidden" name="TYPE" value="NA">

<input type="hidden" name="METHOD" value="MasterCard">

<input type="hidden" name="NAME" value="vern keller">

<input type="hidden" name="ADDRESS" value="1922 some rd">

<input type="hidden" name="CITY" value="phoenix">

<input type="hidden" name="STATE" value="or">

<input type="hidden" name="ZIP" value="82370">

<input type="hidden" name="COUNTRY" value="USA">

<input type="hidden" name="PHONE" value="212-673-4637">

<input type="hidden" name="FAX" value="">

<input type="hidden" name="EMAIL" value="admin@mydomain.com">

<input type="submit" value="Continue">









What I need to do is to have the script it is posting to (myscript.cgi)grab the CUSTID value (in the above example it is 4) and turn that into a variable (such as $CUSTID) for the script it is posting to.......which begins with multiple declarations like the following

require "dacfgv.pl";
$goodreferer = "http://www.goodplace.com/test.html";
$badferer = "http://www.goodplace.com/bad.html";
$adminname = "admin";
$username = "testuser1";
$password = "testpass1";

rest of script.........
Question by:vernk
  • 3

Author Comment

ID: 1830575
Edited text of question

Accepted Solution

oliverp101698 earned 200 total points
ID: 1830576
You can use the ReadParse subroutine that is a part of the
cgi-lib library to read your form data. First you will have
to require cgi-lib, using the following line:

require "/inetpub/scripts/library/cgi-lib.pl";
Note: your path will likely be different, locate the file
on your server first

then the command is:


which creates an associate array (hash) from your form data.
Note: if you don't supply your own hash name (form_data in
the above example) the default name is 'in'

Then you can access your form variables like this:

$CUSTID = $form_data{'CUSTID');

Does that help?


Author Comment

ID: 1830577
 Thank you!......I am running perl 5.0003 and i have searched the directories, but no cgi-lib.pl (i did find CGI.pm in the lib directory) Should i get cgi-lib.pl and put it in the lib directory so I can call it?
 Thanx again for all the help

Author Comment

ID: 1830578
Ok, I tried putting cgi-lib.pl in my cgi-bin.....and added the require and the parse, etc.......

Heres what i am trying to do:
 At the 11th line from the end of this scrip,(print LOG "$FORM{'username'}|$FORM{'name'}|$FORM{'email'}|$FORM{'password'}|$timeStr\n";) it opens LOG and writes the username, name, password, etc to the log file......I want to write the CUSTID value, that was passed from the form in my original message, to this line also. The entire script is below

require "cfgdafpass.pl";
$goodreferer = "http://www.mydomain.com/testvk1.html";
$badferer = "http://www.mydomain.com/else.html";
$htpasswd_FILE = 'D:/host/123.456.789.12/http/test.txt';
$logfile = 'D:/host/123.456.789.12/http/dafcc.log';
$mailprog = '';
$cgiurl = 'http://www.mydomain.com/cgi-bin/dafpass.cgi';
$aua = '1';
$adminmail = "admin\@mydomain.com";
$adminname = "admin";
$adminpwd = "http://www.mydomain.com/admin.pwd";
$homepage = "Daf Cc Signup";
$thirtydays = "2592000";
$user1 = "user1";
$pass1 = "ntpass1";


if($FORM{'action'} eq "regform") { &regform; }
elsif($FORM{'action'} eq "reg") { &reg; }
elsif($FORM{'action'} eq "rmfrm") { &rmfrm; }
elsif($FORM{'u'} eq "Delete User") { &rm; }
elsif($FORM{'a'} eq "Admin Override") { &rma; }
elsif($FORM{'action'} eq "lupfrm") { &lupfrm; }
elsif($FORM{'action'} eq "lup") { &lup; }
elsif($FORM{'action'} eq "apfrm") { &changepass; }
elsif($FORM{'action'} eq "changepass2") { &changepass2; }
elsif($FORM{'action'} eq "gen") { &gen; }
elsif($FORM{'action'} eq "gen2") { &gen2; }
else { &menu; }

sub menu {
if ($ENV{'HTTP_REFERER'} ne $goodreferer) {
       print "Location: $badreferer\n\n";
       exit 0;
print "<center><form action=\"$cgiurl\" method=\"POST\"><input type=\"hidden\" name=\"action\" value=\"regform\">\n";
print "<input type=\"submit\" value=\"Choose Username and Password\"></form><p>\n";
print "<center><form action=\"$cgiurl\" method=\"POST\"><input type=\"hidden\" name=\"action\" value=\"rmfrm\">\n";


sub regform
&Header("Choose","Choose","Username and Password");
print "<center><font color=#000080>Please fill out the form below:</font></center><br>\n";
print "<center><font color=#000080 size=-1><b>Correct email is required or membership will be cancelled</b></font></center><p>\n";
print "<form method=\"POST\" action=\"$cgiurl\"><center>\n";
print "<table border=\"0\" width=\"45%\"><tr>\n";
print "<td width=\"41%\">Name:</td><td width=\"59%\">\n";
print "<input type=\"text\" name=\"name\" size=\"20\"></td></tr>\n";
print "<tr><td width=\"41%\">Email address:</td><td width=\"59%\">\n";
print "<input type=\"text\" name=\"email\" size=\"20\"></td></tr>\n";
print "<tr><td width=\"41%\">Login name:</td><td width=\"59%\">\n";
print "<input type=\"text\" name=\"username\" size=\"20\"></td></tr>\n";
print "<tr><td width=\"41%\">Password:</td><td width=\"59%\">\n";
print "<input type=\"password\" name=\"password\" size=\"20\"></td></tr>\n";
print "<tr><td width=\"41%\">And again:</td><td width=\"59%\">\n";
print "<input type=\"password\" name=\"password2\" size=\"20\"></td></tr>\n";
if($aua eq "0") {
print "<tr><td width=\"41%\">Admin Password:</td><td width=\"59%\">\n";
print "<input type=\"password\" name=\"adpasswd\" size=\"20\"></td></tr>\n";
print "</table><input type=\"hidden\" name=\"action\" value=\"reg\">\n";
print "<input type=\"submit\" value=\"Add User\"></form></center>\n";

sub reg
if($aua eq "0") {
      open(ADM,"$adminpwd") || &error('File Error on password file');
      $adm = <ADM>;
      if($FORM{'adpasswd'} eq $adm) { goto register; }
      else { &error('Invalid password entered.'); }
else {
open(HTPASS,"<$htpasswd_FILE") || &error('Could not find specified file');
@htpasswd = <HTPASS>;

if($FORM{'username'} =~ /:/){&error('Do not use : in your username');}
if($FORM{'username'} =~ /\s/){&error('Do not use spaces in your username');}
if($FORM{'username'} eq ""){&error('No username entered');}
if($FORM{'password'} eq ""){&error('No password entered');}
if($FORM{'password'} ne $FORM{'password2'}){
&error('Your first password did not match your second');}
if(@match = grep(/^$FORM{'username'}:/, @htpasswd)){
&error("The username, $FORM{'username'} is already in use. Please click on back and choose another one.");}

$salt1 = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./';
$salt = substr($salt1,rand(length($salt1)),1);
$salt .= substr($salt1,rand(length($salt1)),1);
$password = crypt($FORM{'password'},$salt);

        $now = time();

        $timeStr = &manageDate( $now );
        print "\$now = $now\n\$timeStr = \"$timeStr\"\n";

sub manageDate
        local( $time_t ) = @_;

        ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime( $time_t );

        $year += 1900;

        $str = sprintf( "%4.4d-%2.2d-%2.2d", $year, $mon, $mday );


open(HTPASS,">>$htpasswd_FILE") || &error('Could not find specified file');
$datestr = &manageDate( $thirtydays+$now );
print HTPASS "$FORM{'username'}:$FORM{'password'}, $ntuser:$ntpass, $datestr\n";

open(LOG, ">>$logfile") || &error('Could not find specified file');
print LOG "$FORM{'username'}|$FORM{'name'}|$FORM{'email'}|$FORM{'password'}|$timeStr\n";

&Header("Membership Confirmation","Please Continue");
print "<center><font color=#000080>Thank You $FORM{'name'}!</font></center><p>\n";
print "<center>Please <a href=\"http://www.mydomain.com/home.htm\"><b> CONTINUE</b></a></center>";

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question