Hi All,
I modified the user registration script, but not sure how to make it check for each variable in terms of preventing junk registration and invalid characters?
Two codes below :
a) html
b) perl script (print and inserting into database)
Cheers...
Andrew
a) html
=====
b) perl script
=========
I modified the user registration script, but not sure how to make it check for each variable in terms of preventing junk registration and invalid characters?
Two codes below :
a) html
b) perl script (print and inserting into database)
Cheers...
Andrew
a) html
=====
Code:
<!DOCTYPE HTML PUBLIC "-//SoftQuad//DTD HTML 3.2 + extensions for HoTMetaL PRO 3.0(U) 19961211//EN" "hmpro3.dtd"> <HTML> <HEAD> <TITLE></TITLE></HEAD> <BODY> <FORM ACTION="/cgi-bin/acctman2.pl" METHOD="POST"> <CENTER> <TABLE BORDER="0" WIDTH="400"> <TR> <TD ALIGN="CENTER"> <TABLE BORDER="0" CELLPADDING="5" BGCOLOR="#FF8000"> <TR> <TD><INPUT TYPE="CHECKBOX" NAME="agree" VALUE="agree"></TD> <TD><FONT SIZE="-1" FACE="verdana, arial, helvetica"><B>I agree to the Terms and Conditions above.</B></FONT></TD></TR></TABLE><BR></TD></TR> <TR> <TD> <HR SIZE="2" NOSHADE="NOSHADE"></TD></TR> <TR> <TD ALIGN="CENTER"> <TABLE BORDER="0" WIDTH="350" NOWRAP="NOWRAP"> <TR> <TD><FONT SIZE="-1" FACE="verdana, arial, helvetica"><B>Customer Information</B></FONT><BR><FONT SIZE="-2" FACE="verdana, arial, helvetica" COLOR="#FF0000"><B>Fields marked with an asterisk<BR>are required input fields.</B></FONT><BR><BR></TD></TR> <TR> <TD><INPUT TYPE="TEXT" NAME="fname"> <FONT SIZE="-1" FACE="verdana, arial, helvetica">First Name *</FONT></TD></TR> <TR> <TD><INPUT TYPE="TEXT" NAME="lname"> <FONT SIZE="-1" FACE="verdana, arial, helvetica">Last Name *</FONT></TD></TR> <TR> <TD><INPUT TYPE="TEXT" NAME="email"> <FONT SIZE="-1" FACE="verdana, arial, helvetica">E-Mail Address *</FONT></TD></TR></TABLE> <TABLE BORDER="0" WIDTH="350" NOWRAP="NOWRAP"> <TR> <TD><BR><FONT SIZE="-1" FACE="verdana, arial, helvetica"><B>Choose a User Name</B></FONT><BR><INPUT TYPE="TEXT" NAME="username"> <FONT SIZE="-1" FACE="verdana, arial, helvetica">User Name</FONT> <FONT SIZE="-1" FACE="arial, helvetica"><BR><BR><B>Choose a Password</B></FONT><BR> <INPUT TYPE="password" NAME="pwd"> <FONT SIZE="-1" FACE="verdana, arial, helvetica">Password</FONT><BR><INPUT TYPE="password" NAME="pwd2"> <FONT SIZE="-1" FACE="verdana, arial, helvetica">Verify Password</FONT></TD></TR></TABLE><BR><BR><INPUT TYPE="SUBMIT" NAME="process" VALUE="Submit My Order"><INPUT TYPE="RESET" NAME=""></TD></TR> <TR> <TD> <HR SIZE="2" NOSHADE="NOSHADE"></TD></TR></TABLE></CENTER></FORM></BODY></HTML>
b) perl script
=========
Code:
#!c:\perl\bin\perl.exe #!/usr/bin/perl ############################################ ## ## ## Account Manager LITE User Signup ## ## by SiteInteractive.com ## ## http://siteinteractive.com/contact ## ## ## ## version: 1.09 ## ## last modified: 07/24/2002 ## ## copyright (c) 1998 - 2002 ## ## ## ## latest version is available from ## ## http://SiteInteractive.com ## ## ## ############################################ # # Copyright 1998 Elite Host. All Rights Reserved. # # TERMS OF USE # 1. Account Manager is for licensed customers # only. Customer may use Account Manager as many # times as customer wishes, as long as customer owns or runs the web # site that Account Manager is installed on. Account # Manager may not under any circumstances be sold # or redistributed without the written consent of CGI Script Center and # its owner Diran Alemshah. # # 2. CGI Script Center, at its own discresion, will decide if any terms # of the this agreement have been violated by customer. Upon written e- # mailed notification to Customer of Terms of Use violations, CGI # Script Center may revoke customer's license to use Account Manager. # In that event, Customer agrees to any and all of the following: # # a) Customers found in violation of this agreement, found reselling or # redistributing Account Manager, or making # Customers Members Area ID and password public to anyone in any # manner will forfeit their Members area password and all rights to # future versions of Account Manager. # # b). Customer will no longer be licensed to run any version of # Account Manager. # # Indemnification # 1. Customer agrees that it shall defend, indemnify, save and hold # CGI Script Center, Elite Web Design and marketing, and any # persons affiliated with either company, harmless from any and all # demands, liabilities, losses, costs and claims, including reasonable # attorney's fees asserted against CGI Script Center, its agents, its # customers, officers and employees, that may arise or result from any # service provided or performed or agreed to be performed or any product # sold by customer, its agents, employees or assigns. Customer agrees to # defend, indemnify and hold harmless CGI Script Center, its agents, # its cusomters, officers, and employes,against # liabilities arising out of; a) any injury to person or property caused # by an products sold or otherwise distributed in connection with CGI # Script Center products; (b) any material supplied by customer # infringing or allegedly infringing on the proprietary rights of a # third party; c) copyright infringement and (d) any defective products # sold to customer from CGI Script Center products. # # This program may not be distributed in whole or part, freely, for pay, # or any other form of compensation. # ################################################## ############### # This version designed for Win32 systems (NT). If you require # a Unix version, please contact cgi@elitehost.com ################################################## ############### ################################################## ############ # EDIT USER CONFIGURATIONS BELOW ################################################## ############ # apache is in d DRIVE!!! not C #require "d:/program files/apache software foundation/apache2.2/cgi-bin/config.pl"; # This completes this portion of your Account Manager setup ################################################## ############ # DO NOT EDIT BELOW THIS LINE ################################################## ############ use CGI; use CGI::Carp qw(fatalsToBrowser); use DBD::mysql; use DBI; my $query = CGI->new; unless ($CGI::VERSION >= 2.47) { error('Your version of CGI.pm is too old. You must have verison 2.47 or higher to use this script.') } #SECTION B #========================================= #Database initialization and initial query my ($dbh, $data_source); my $mysql_server_name = 'localhost'; my $mysql_database_name = 'test'; my $mysql_user_name = 'root'; my $mysql_password = 'mysql1'; my $data_source = 'DBI:mysql:' . $mysql_database_name . ':' . $mysql_server_name; my $dbh = DBI->connect( $data_source, $mysql_user_name, $mysql_password, {RaiseError=>1}) || die "$DBI::errstr"; #important line to pass email address from html to perl my $agree_field = $query->param("agree") || 'Annonymous'; my $first_name = $query->param("fname") || 'Annonymous'; my $last_name = $query->param("lname") || 'Annonymous'; my $email_address = $query->param("email") || 'Annonymous'; my $user_name = $query->param("username") || 'Annonymous'; my $password = $query->param("pwd") || 'Annonymous'; # End of Database initial Query #========================================== print $query->header(), $query->start_html(-title=>'Input Successful'), $query->p('Thanks for registrating your particulars with us!'), $query->p("You Agree? : $agree_field:"), $query->p("Your First Name : $first_name"), $query->p("Your last Name : $last_name"), $query->p("Your email address: $email_address"), $query->p("Your username : $user_name"), $query->p("Your Password : $password"), $query->end_html; sub error { print $query->header(), $query->start_html(-title=>'Error'), shift, $query->end_html; exit(0); } my $sql = $dbh->prepare(qq{SELECT * FROM user_reg}); $sql->execute(); while (my @data = $sql->fetchrow_array()) { # Print the date from the first two columns in the table #print $data[0], "\t", $data[1], "<br>"; print $data[0], "\t", $data[1], "\t", $data[2], "\t", $data[3], "\t", $data[4], "\t", $data[5], "<br>"; } 1; $sql = $dbh->prepare(qq{insert into user_reg(agree_field, first_name, last_name, email_address, user_name, password) values ( "$agree_field", "$first_name", "$last_name", "$email_address", "$user_name", "$password") } ); $sql->execute() or die "$dbh->errstr\n";; $sql = $dbh->prepare(qq{SELECT * FROM user_reg}); $sql->execute(); while (my @data = $sql->fetchrow_array()){ # Print the date from the first four columns in the table print $data[0], "\t", $data[1], "\t", $data[2], "\t", $data[3], "\t", $data[4], "\t", $data[5], "<br>"; } 1;
Comment