CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Need some help with this

 



Mel
Deleted

May 22, 2000, 3:59 PM

Post #1 of 8 (1121 views)
Need some help with this Can't Post

can anyone tell me what's wrong with the following code?

$username = $FORM{'username'};
$password = $FORM{'password'};

open(DATA, "zach");

@data = <DATA>;
while (($username ne "$usrname") and ($password ne "$pwd")) {
$theline = "$_";
chomp($theline);
($usrname, $pwd, $location) =
split(/::/, $theline);
}
print "Location: $location\n\n";


perlkid
stranger

May 24, 2000, 1:01 AM

Post #2 of 8 (1120 views)
Re: Need some help with this [In reply to] Can't Post

 
What Type of error are you getting and what are you using this code for? I know a few different methods if your trying to do what I think you are.

Perlkid


Mel
Deleted

May 24, 2000, 12:49 PM

Post #3 of 8 (1120 views)
Re: Need some help with this [In reply to] Can't Post

I am getting a 500 server error. What i am trying to do is write something that will take a username and password that a user enters and then open a file and go to a certain url for the username/password that the pers entered.

Thanks


TheGame+
Deleted

May 24, 2000, 1:17 PM

Post #4 of 8 (1120 views)
Re: Need some help with this [In reply to] Can't Post

Your script is seriously garbled - I can only hope this is just a bad cut & paste, and not the original script...

Anyway, assuming the users, passes and URLs are in the file 'zach', and that that file happens to be located in the current directory where the script is executed (who knows, you might get lucky), here's a slightly better script :

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

use CGI qw/:standard/;
use CGI::Carp qw(fatalsToBrowser);
$username = param('username');
$password = param('password');
$url = "http://some.default.url/if_they're_wong/";

open(DATA,"<zach") &#0124; &#0124; die "Sorry, I can't open file 'zach' - $!\n";
while (<DATA> ) {
chomp;
next if /^$/; # skip empty lines
($user, $pwd, $location) = split(/::/);
if (($user eq $username) && ($pwd eq $password)) {
$url = $location;
last;
}
}
close(DATA);
print redirect($url);
</pre><HR></BLOCKQUOTE>

An absolute path to your 'zach' file would help if you get the "Sorry, I can't open..." error.


perlkid
stranger

May 24, 2000, 9:13 PM

Post #5 of 8 (1120 views)
Re: Need some help with this [In reply to] Can't Post

 
I agree with TheGame Mel.

perlkid


Mel
Deleted

May 25, 2000, 12:37 PM

Post #6 of 8 (1120 views)
Re: Need some help with this [In reply to] Can't Post

TheGame,
just out of curisity, what did you think was so grabled about the code I posted, was it the formatting or what?


TheGame+
Deleted

May 25, 2000, 11:48 PM

Post #7 of 8 (1121 views)
Re: Need some help with this [In reply to] Can't Post

Do you really want to know ?

OK, you posted this to the 'intermediate' board after all, so I suppose you know some Perl already, and have already written a few scripts Smile

Here are my comments, in decreasing order of importance (at least for me) :

1) this script will loop forever if $username and $password are not empty

You forgot the while (<DATA> ) loop to feed some values to $_.

2) it will print out an empty Location header if the user/pass is NOT correct (or empty)

I don't think the webserver will like that, and I'm sure the user won't like it either...

3) you assume that the script is run in its own directory (which may be true or not), and don't check whether the open succeeded.

4) you don't close the DATA file.

Normally, the system will do that for you when the script finishes executing, but it's not a clean way of handling files.

5) you use an outdated way of dealing with CGI variables - that is, assuming you DO have some routine to fill in the %FORM hash that you didn't show here.


Mel
Deleted

May 26, 2000, 12:36 PM

Post #8 of 8 (1120 views)
Re: Need some help with this [In reply to] Can't Post

Thanks for your comments, I am always open for them and I like to hear them because they help me to see things that maybe I would'nt have otherwise. I understand what yo're saying in those comments, but, just so you know I understand those problems and that code was just a rough representation of what I was trying to accomplish, also that was just a piece of the pie, I had already taken care of things like the form hash. But, again thanks for your comments.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives