
sleuth
Enthusiast
Nov 11, 2000, 2:08 PM
Post #12 of 12
(9632 views)
|
Ok, Sorry about that, I got you mixed up with someone else who was on windows and I wrote it for win32 platforms. But here it is. Just edit my message and you can cut & paste it really easily. <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> #!/usr/bin/perl ######################################################################################################################################################################## sub parse_form { my (@pairs, %in); my ($buffer, $pair, $name, $value); if ($ENV{'REQUEST_METHOD'} eq 'GET') { @pairs = split(/&/, $ENV{'QUERY_STRING'}); } elsif ($ENV{'REQUEST_METHOD'} eq 'POST') { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); } else { &cgierr('You cant run this script from telnet/shell.'); } PAIR: foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; ($value eq "---") and next PAIR; exists $in{$name} ? ($in{$name} .= "~~$value") : ($in{$name} = $value); } return %in; } ######################################################################################################################################################################## %in =&parse_form; print "Content-type: text/html\n\n"; $data = "test.db"; $user = $in{'user'}; $first_name = $in{'first_name'}; $last_name = $in{'last_name'}; $email = $in{'email'}; $password = $in{'password'}; $ok_message = qq~ <p align="center">Your Information Was Successfully Added</p> ~; $notok_message = qq~ <p align="center">Sorry, That User Name Already Exists. <br><br><a href = "javascript:history.go(-1);">Back</a> </p> ~; $error_message = qq~ <p align="center">Please Fill out all the required fields. <br><br><a href = "javascript:history.go(-1);">Back</a> </p> ~; $bademail_message = qq~ <p align="center">Please Submit A Valid Email address. <br><br><a href = "javascript:history.go(-1);">Back</a> </p> ~; if (!$user | | !$first_name | | !$last_name | | !$email | | !$password){ print "$error_message"; exit; } if ($email !~ m,.*?\@.*?\.(.*),){ print "$bademail_message"; exit; } if (-e "$data"){}else{ open(make, ">$data"); print make ""; close(make); } open(file, "<$data"); while(<file> ){ (@res)=split(/\|\^\|/, $_); if ($res[2] eq "$user"){ $dontadd = "1"; } }close(file); if (!$dontadd){ open(data, ">>$data"); print data "$first_name|^|$last_name|^|$user|^|$password|^|$email|^|\n"; close(data); print "$ok_message"; }else { print "$notok_message"; } </pre><HR></BLOCKQUOTE> The html has to be like this. <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <meta name="GENERATOR" content="Microsoft FrontPage 4.0"> <meta name="ProgId" content="FrontPage.Editor.Document"> <title></title> </head> <body> <p> <form action="http://www.site.com/test.cgi" method="POST"> <div align="center"><center><table BORDER="0" CELLPADDING="0" width="365"> <tr> <td width="189"><div align="right"><p><font face="Verdana" size="2"><b>Choose username:</b></font> </div> </td> <td width="14"></td> <td width="152"><small><input NAME="user" TYPE="text" SIZE="20,1" MAXLENGTH="100"></small></td> </tr> <tr> <td width="189"><div align="right"><p><font face="Verdana" size="2"><b>First Name:</b></font> </div> </td> <td width="14"></td> <td width="152"><small><input NAME="first_name" TYPE="text" SIZE="20,1" MAXLENGTH="100"></small></td> </tr> <tr> <td width="189"><div align="right"><p><font face="Verdana" size="2"><b>Last name:</b></font> </div> </td> <td width="14"></td> <td width="152"><small><input NAME="last_name" TYPE="text" SIZE="20,1" MAXLENGTH="100"></small></td> </tr> <tr> <td width="189"><div align="right"><p><font face="Verdana" size="2"><b>Password:</b></font> </div> </td> <td width="14"></td> <td width="152"><small><input type="text" name="PASSWORD" size="20"></small></td> </tr> <tr> <td width="189"><div align="right"><p><font face="Verdana" size="2"><b>email address:</b></font></td> <td width="14"></td> <td width="152"><small></small><input type="text" name="email" size="20"><small></small></td> </tr> </table> </center></div><div align="center"><center><p><br> <br> <input TYPE="submit" VALUE="submit"></p> </center></div> </form> </body> </html> </pre><HR></BLOCKQUOTE> Ok, so try that now, It should work on any unix system, The other one used a module you may not have. Sleuth
|