|
#!/usr/bin/perl &parse_form; print "Content-type:text/html\n\n"; if ($v{'id'} < 4000000 || $v{'id'} > 9999999 || !$v{'passwd'}) { print 'Invalid information : error'; exit; } $filename = 'data.txt'; open(myfile,"$filename"); @getrec = <myfile>; close(myfile); foreach $rec (@getrec) { ($id,$passwd) = split(',',$rec); if ($id eq $v{'id'}) { print 'Duplicate information : error'; exit; } } open(myfile,">>$filename"); print myfile "$v{'id'},$v{'passwd'},\n"; close(myfile); print "Add new record : ok"; sub parse_form { @pairs = split(/&/,<STDIN>); foreach $pair (@pairs) { local($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 =~ s/,/,/g; $v{$name} = $value; } } |