Array Problem
Hello! I hope someone can help me. I am working on the following code, written to accomplish these tasks: 1)Accept username and password from an HTML page 2)Open a text file and store the username and passwords listed there in an array 3)Compare the username and password in the array to the username and password entered on the HTML page. 4)If username and password match, direct the user to another web page. 5) If username and password do not match or fields are left blank on the HTML form, direct user to an error page. Currently, the array seems to only be picking up the last name listed in the text file. Would you please take a look at my code to help me see what I have done wrong? Thanks, Maureen #!/usr/local/bin/perl require "cgi-lib.pl"; #process incoming form data &ReadParse; #open the database in read-only mode open(FILE,"pwdata.txt") || die "Can't find database\n"; #store database contents in an array and close file @indata = ; close(FILE); foreach $i (@indata) { #remove hard return character from each record chomp($i); #split fields on pipe character #assign a variable name to each of the fields ($username,$password) = split(/\|/,$i); } #check for blank form fields if ($in{'username'}eq"" || $in{'password'}eq"") { #set content type } #check for proper password if ($username!=~/$in{'username'}/) { #invalid password--create error message and exit print &PrintHeader; print <<"PrintTag"; Error! Authorization Required You do not have authorization to enter this website. Please click http://www.worldwidewebstrategies.com";>here to return to the WWWS web site. If you feel you have received this message in error, please return to the login screen and try to enter your username and password again. PrintTag exit(0); } #check for existence of lock file if (-e "lock.fil") { #lock file exists! print message & shut down print &PrintHeader; print <<"PrintTag"; File in use Try again! The database is in use. Please try again later. PrintTag exit(0); } #everything is okay. Create lock file. open(LOCK_FILE, ">lock.fil"); #open, append record, and close database open(FILE,">>data.txt") || die "Can't find database\n"; print FILE "$in{'username'}|$in{'password'}\n"; close(FILE); #close lock file close(LOCK_FILE); #delete lock file unlink("lock.fil"); #print database contents print "Location:http://www.worldwidewebstrategies.com\n\n";; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Param problem
--- Håkan Edman <[EMAIL PROTECTED]> wrote: > Hi > > I have a script that generates a HTML page with input fields. The amount > of fields depends of an ascii database. This means that I don't know how > many > fields I have to work with. I tried the following code but I don't get > any > data in $title and $path. I get the correct amount of entrys but it > looks like: > 0|| > 1|| > 2|| > And so on. > > CODE: > >$E=0; >open (EDITERA, ">$DATABASE") || die "Can't open $DATABASE!\n"; > foreach $h (@num) { > > $title= param('linkname$E'); > $path = param('path$E'); > print EDITERA "$E|$title|$path\n"; > $E++; >} > >close (EDITERA); > > > Is there some easy way to get this to work? > > regards > Håkan Håkan, It's easy to get this to work, but you have some problems here. Consider the following three lines of code: $title= param('linkname$E'); $path = param('path$E'); print EDITERA "$E|$title|$path\n"; The reason that $title and $path are not getting any data is because variables will not interpolate in single quotes. You need to change those to double quotes: $title= param("linkname$E"); $path = param("path$E"); However, you then print this data directly to your text file without checking what is in the data. What happens if someone sends a newline? What happens if someone sends data with a pipe in it? The pipe alone will cause subsequent reading of the database to be off because it will appear to have extra delimited fields. There are other dangers here, but lets assume, for the sake of argument, that the title and path can only be letters, underscores, whitespace, digits, dots and forward slashes. Further, let's assume that the title can not be more than 30 characters and the path cannot be more than 100. We can create some regular expressions to untaint your data very easily. $_title = param("linkname$E"); $_path= param("path$E"); my ( $title ) = ( $_title =~ !^([\s\w\d./]{1,30})! ); my ( $path ) = ( $_path =~ !^([\s\w\d./]{1,100})! ); print EDITERA "$E|$title|$path\n"; You'll probably need to modify the regular expressions to fit your needs, but this is much safer and bug-free than what you are currently doing. Hope this help. Cheers, Curtis "Ovid" Poe = "Ovid" on http://www.perlmonks.org/ Someone asked me how to count to 10 in Perl: push@A,$_ for reverse q.e...q.n.;for(@A){$_=unpack(q|c|,$_);@a=split//; shift@a;shift@a if $a[$[]eq$[;$_=join q||,@a};print $_,$/for reverse @A __ Do You Yahoo!? Send FREE video emails in Yahoo! Mail! http://promo.yahoo.com/videomail/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Tables in CGI
I was watching this correspondance earlier, and wondering why you are not using fetchrow_hashref. I now wonder why you get all the rows of data bundled into a single array. Does your interface have now way of returning data one row at a time? A simple solution to your problem would go along the lines of my $rows =''; while (@data) # is the array empty yet? { my $row = "\n";# just to layout the HTML for readability for (0..$#columns) { my $element = shift @data; $row .= td( $element ) } $rows .= Tr($row) } print table({-border=>'1', -align=>'CENTER', -valign=>'TOP'}, Tr({-align=>'CENTER', -valign=>'TOP'}, [ th(\@columns) ] ), $rows ) - Roger - - Original Message - From: "Gerry Jones" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, January 15, 2002 4:11 PM Subject: Re: Tables in CGI > Thanks for your suggestions. I went back and tried some of them with no luck > I'm afraid. Here's my code as it is now: > > print table({-border=>'1', -align=>'CENTER', -valign=>'TOP'}, > Tr({-align=>'CENTER', -valign=>'TOP'}, > [ > th(\@columns), > td(\@data) > ] > ) > ) > > I tried using map as suggested by Briac Pilpré, but that gave the same output. > > Here's an example of what the arrays could contain from a PostgreSQL table > called "Components" (stored as "text" within the DB): > > @columns: > Subtype > Type > Components > > @data: > Celeron 766 > Computer > Lots of stuff > Pentium 2 > Computer > More Stuff > ... > ... > > I've checked the contents of each array (by printing them to the browser) and > they seem correct. > > Here I want a table 3 columns across and "x" rows down, but what I get is 3 > columns across, and @data scpread out across one row. Another table may > require 5 columns across. Problem is I don't know how to code the correct way > using CGI.pm. > > Thanks, > > Gerry. > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Tables in CGI
Thanks for your suggestions. I went back and tried some of them with no luck I'm afraid. Here's my code as it is now: print table({-border=>'1', -align=>'CENTER', -valign=>'TOP'}, Tr({-align=>'CENTER', -valign=>'TOP'}, [ th(\@columns), td(\@data) ] ) ) I tried using map as suggested by Briac Pilpré, but that gave the same output. Here's an example of what the arrays could contain from a PostgreSQL table called "Components" (stored as "text" within the DB): @columns: Subtype Type Components @data: Celeron 766 Computer Lots of stuff Pentium 2 Computer More Stuff ... ... I've checked the contents of each array (by printing them to the browser) and they seem correct. Here I want a table 3 columns across and "x" rows down, but what I get is 3 columns across, and @data scpread out across one row. Another table may require 5 columns across. Problem is I don't know how to code the correct way using CGI.pm. Thanks, Gerry. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
execute an bash-script
Hallo beginners-cgi, i want to execute a bash-script from a perl-cgi-script. if a special perl-script is executed in my cgi-bin, i want to receive a winpopup-message on my workstation. i tried this with exec(), but the parameter $popup worries my apache ,-) if i call the script from the commandline, the popup-message is sent. why not from my perl-cgi-script? here i go ;-) perl-script === ... $popup = "Sample popup-message"; exec ('/usr/local/myperl/smb-popup',$popup); ... === perl-script === === smb-popup === #!/bin/bash echo "$1" | smbclient -M testhost -U myserver === smb-popup === -- MfG... ...Olav FidoNet: 2:240/5138 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Param problem
Hi I have a script that generates a HTML page with input fields. The amount of fields depends of an ascii database. This means that I don't know how many fields I have to work with. I tried the following code but I don't get any data in $title and $path. I get the correct amount of entrys but it looks like: 0|| 1|| 2|| And so on. CODE: $E=0; open (EDITERA, ">$DATABASE") || die "Can't open $DATABASE!\n"; foreach $h (@num) { $title= param('linkname$E'); $path = param('path$E'); print EDITERA "$E|$title|$path\n"; $E++; } close (EDITERA); Is there some easy way to get this to work? regards Håkan -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Installing Net:SMTP module on Linux 7.1
Thomas Smidt wrote: > I'm a very new beginner to both Perl and Linux, but to get a specific program > to run (twiki.org) I need to install the Net::STMP Perl Module on Linux 7.1. > I have downloaded the .tar.gz file but need either a good descriptive web site > or someone to walk me through installing the module. I have a limited i use makerpm.pl to install all my perl stuff on redhat. you can get it from here: http://www.cpan.org/authors/id/J/JW/JWIED/ here's the procedure. as root, copy makerpm.pl and your gzipped source file to /usr/src/redhat/SOURCES run makerpm, then build your rpm like this, substituting your file in for source_code: % ./makerpm.pl --specs --source source_code.tgz % cd ../SPECS/ % rpm -ba -v source_code.spec % cd ../RPMS/i386/ % rpm -Uvvh perl-source_code.i386.rpm note that if you are missing any perl modules required for the one you're installing, you'll be told so during the 1st step. also note that makerpm will prepend a 'perl-' to the source_code name when it creates the .i386.rpm. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: tables in cgi for briac pilpre'
Nafiseh Saberi wrote (in perl.beginners): > hi. > hope you be fine. > i reply this question,also. > (tables in cgi) > do you know what is the difference between my answer > and yours,or what is the advantages ?? Your answer is probably faster than mine in execution time since you don't have to call CGI methods to print a HTML table. However, using CGI.pm to create HTML, is in my opinion, a safeguard against HTML inconstencies. I think also makes the code more readable, as it is 100% perl and not a mix between perl and HTML. And an added bonus is that CGI.pm outputs by default (generally) valid XHTML. Of course, if you want to make really complex things in HTML, CGI.pm can be limitating. But in these case, I'll probably use a proper Templating tool (like HTML::Template, or better, Template Toolkit or HTML::Mason, all available on CPAN) I hope all of this makes sense! > I think..your mail have problem and returned. Yes, my mail is 'spam armored', you have to remove the capital words 'NO' and 'SPAM' from my address. Briac -- briac << dynamic .sig on strike, we apologize for the inconvenience >> -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Tables in CGI
I am not a perl expert by a very very long way but I remeber solving something like this once by outputting a separate as I iteratred over the results from a query. Hope it helps F -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Tables in CGI
In article <02011510194302.01235@gandalf>, Gerry Jones wrote: > To recap: I don't need help with DBI or querying DB's, but with printing the > results into a table. I have two arrays: "@columns" (contains the column > names from the queried table), and "@data" (contains every row from that > table). I tried to adapt the code in Lincoln Stein's book, but all I got was > a table with the column headings and the first row was filled with the > "@data" array. Here's how I would probably do it using 'pure' CGI.pm. I assume that @data is an array of arrays, each sub-array being a row. #!/usr/bin/perl -w use strict; use CGI qw(:html); my @columns = qw( FooBar Baz Quux ); my @datas =([qw( Eenie Meenie )], [qw( Barney FredWilma)], [qw( Just Another Perl Hacker )], ); print start_html('CGI Table'), table( { -border => 1 }, Tr( [ th(\@columns), map {td($_)} @datas, ]) ), end_html(); __END__ -- briac << dynamic .sig on strike, we apologize for the inconvenience >> -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Tables in CGI
I've deleted the snippet of code I had to display the table since it didn't work. I've tried other methods and they didn't work either. I've seen people using "map" too, but I don't know much about using it. What I meant by consistent was to use Stein's CGI.pm throughout my code. To recap: I don't need help with DBI or querying DB's, but with printing the results into a table. I have two arrays: "@columns" (contains the column names from the queried table), and "@data" (contains every row from that table). I tried to adapt the code in Lincoln Stein's book, but all I got was a table with the column headings and the first row was filled with the "@data" array. Nafiseh Saberi has the right idea, but I would like to do it in "pure" CGI.pm. Thanks, Gerry. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Tables in CGI
hi. hope you be fine. I am working like you..:) test it... my $sql_main = "SELECT name,famil FROM $main_table where famil='$USERNAME' ORDER BY name"; $sth = $dbh->prepare($sql_main) and print "View Users \n" or die print "Cannot prepare sql statement: $sql_main $DBI:: errstr"; my $rc = $sth->execute or die print "Cannot execute sql statement: $sql_main $DBI::errstr"; print ""; print "\n"; print "\n"; # Field name headings (one would only print one set of headings) @name = @{$sth->{'NAME'}}; foreach my $head (@name) { print "$head\n"; } print "Account\n"; while(@row = $sth->fetchrow_array) { print "\n"; foreach my $field (@row) { print "$field\n"; } print "\n"; } print "\n"; print "\n Number of rows returned: ", $sth->rows, "\n"; _ Have a nice day Sincerely yours Nafiseh Saberi The amount of beauty required to launch one ship. < I appreciate your sugesstions > - Original Message - From: "Gerry Jones" <[EMAIL PROTECTED]> To: "CGI Beginners" <[EMAIL PROTECTED]> Sent: Monday, January 14, 2002 19:51 PM Subject: Tables in CGI > I've been tormented by a very small problem. I'm trying to display the > results of a database query using CGI. What I've done is create subroutines > to return the names of the table columns and another to return the data, both > of which are stored in seperate arrays. So I have my data, but the table just > doesn't come out right. The problem is the arrays can be of different sizes, > and I'm finding it really difficult to code a dynamic table using CGI. I > could do it in pure HTML easily, but that's not the point: I'm trying to keep > my code consistent. I've searched the 'net but the solutions I found didn't > work. > > Thanks in advance, > > Gerry. > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]